Hi, I'm very much a newbie to dynamic arrays so apologies if this seems like a trivial question. I have the following vba code, which reads down a column adding the activecell value to the array...it seems to work okay. The reason why I'm wanting to use dynamic arrays is because the number of cells containing values varies.
Sub dynamarray()
Dim DA() As Variant
Dim i As Integer
i = 1
Do Until IsEmpty(ActiveCell.Offset(1, 0))
ReDim Preserve DA(i)
DA(i) = ActiveCell.Value
ActiveCell.Offset(1, 0).Select
i = i + 1
Loop
End Sub
However, I tried extending it to read into the array the value of the activecell and the value of the cell immediately next door (i.e. A1 and B1, A2 and B2 etc.) using the following,
Sub dynamarray()
Dim DA() As Variant
Dim i As Integer
Dim j As Integer
i = 1
j = 1
Do Until IsEmpty(ActiveCell.Offset(1, 0))
ReDim Preserve DA(i, j)
DA(i) = ActiveCell.Value
DA(j) = ActiveCell.Offset(0, 1).Value
ActiveCell.Offset(1, 0).Select
i = i + 1
j = j + 1
Loop
End Sub
...and it doesn't work. Please help, any suggestions comments would be warmly welcomed.
Thanks in advance,
Lochnagar
Sub dynamarray()
Dim DA() As Variant
Dim i As Integer
i = 1
Do Until IsEmpty(ActiveCell.Offset(1, 0))
ReDim Preserve DA(i)
DA(i) = ActiveCell.Value
ActiveCell.Offset(1, 0).Select
i = i + 1
Loop
End Sub
However, I tried extending it to read into the array the value of the activecell and the value of the cell immediately next door (i.e. A1 and B1, A2 and B2 etc.) using the following,
Sub dynamarray()
Dim DA() As Variant
Dim i As Integer
Dim j As Integer
i = 1
j = 1
Do Until IsEmpty(ActiveCell.Offset(1, 0))
ReDim Preserve DA(i, j)
DA(i) = ActiveCell.Value
DA(j) = ActiveCell.Offset(0, 1).Value
ActiveCell.Offset(1, 0).Select
i = i + 1
j = j + 1
Loop
End Sub
...and it doesn't work. Please help, any suggestions comments would be warmly welcomed.
Thanks in advance,
Lochnagar