i am trying display the result of an array into a body of an email but I get an error subscript out of range
I am not yet well understood in manipulating arrays so Im having trouble solving the error
could anyone help me?
Dim lRow As Long
Dim sBody, y
Dim location_sheet As String
Dim sq(), ar, x As Long, j As Long, jj As Long
y = 2
lRow = Cells(Rows.Count, 4).End(xlUp).Row
For Each c In Worksheets("Addresses").Range("D2:D" & lRow).Cells
location_sheet = c.Value
ar = Sheets(location_sheet).UsedRange
For j = 1 To UBound(ar)
For jj = 1 To UBound(ar, 2)
If ar(j, jj) <> "" Then
ReDim Preserve sq(x)
sq(x) = ar(j, jj)
x = x + 1
End If
Next
Next
sBody = "Hi,"
Do While y <= x
sBody = sBody & vbNewLine & sq(y) ' subscript out of range sq(y)
y = y + 1
Loop
With CreateObject("outlook.application").createitem(0)
.To = c.Offset(0, -1).Value
.Subject = c.Offset(0, -3).Value & " " & c.Offset(0, -2).Value & "-" & c.Value
.body = sBody
'.Attachments.Add
.display '.send
End With
Next