Hi All,

On sheet1 I have a data table with a fixed number of columns and a variable number of rows. I'd like to write a script that runs through column A and adds all the values from that row to an array. I keep getting an error on my ReDim step. Hoping one of you has a solution!

Thanks in advance!

Alex

Sub ArrayTesting()
Dim MyArray() As Variant
Dim NumCols As Integer
Dim NumRows As Integer
Dim i As Integer
Dim j As Integer
Dim cell As Range

NumCols = 3
NumRows = Cells(Rows.Count, 1).End(xlUp).Row

ReDim MyArray(1 To NumRows, 1 To NumCols)

i = 1
For Each cell In Worksheets("Sheet1").Range("A1:A" & NumRows).Cells
    If cell.Value = "A1" Then
        ReDim Preserve MyArray(1 To i, 1 To NumCols)
            For j = 1 To NumCols
                MyArray(i, j) = Cells(i, j).Value
            Next j
    End If
    i = i + 1
Next cell

'print results
For i = 1 To NumRows
    For j = 1 To NumCols
        Debug.Print MyArray(i, j)
    Next j
Next i

End Sub