In an effort to try to not use named ranges on helper worksheets I would like to see if I can write to a 2D array and use the data in that to populate userforms. I have little knowledge of arrays and might be going the wrong way about it. This code will load two columns but not 3 or 4. I would also like to refer the columns by number rather than letter. Any pointers appreciated.
Sub StoreRange()
Dim MyArray() As String, asheet As Worksheet
Dim iloop As Integer
Dim x As Variant
ReDim MyArray(0)
Dim LastRow As Long
Set asheet = ActiveSheet
With asheet
LastRow = .Range("a" & Rows.Count).End(xlUp).Row
For Each x In .Range("a1:A" & LastRow, "e1:e" & LastRow).Cells
'For Each x In .Range("a1:A" & LastRow, "e1:e" & LastRow, "j1:j" & LastRow, "n1:n" & LastRow).Cells
MyArray(UBound(MyArray)) = x
ReDim Preserve MyArray(UBound(MyArray) + 1)
Next
ReDim Preserve MyArray(UBound(MyArray))
For iloop = LBound(MyArray) To UBound(MyArray)
Debug.Print MyArray(iloop)
Next
End With
End Sub
sample attached
Bookmarks