Adding to an array
If you are sure you need both arrays:
Sub Test()
Dim Array1() As String
Dim Array2() As String
ReDim Array1(1 To 3)
For i = 1 To 3
Array1(i) = Format$(i)
Next i
Array2 = Array1
ReDim Preserve Array2(1 To UBound(Array2) + 1)
Array2(4) = "4"
For i = 1 To UBound(Array2())
Debug.Print Array2(i)
Next i
End Sub
You can also copy the values from Array1 to Array2, one element at a time, in
a For/Next loop, i.e.
For i = 1 to Ubound(Array1())
Array2(i) = Array1(i)
Next i
On Sun, 24 Oct 2004 12:52:32 -0400, "Otto Moehrbach"
wrote:
Excel 2002, WinXP
Let's say I have an array, MyArray, consisting of A, B, C. (Strings only)
Now lets say that I want to build another array, OtherArray, consisting of
the same A, B, C, but having D as well. I know that I can build the
OtherArray as simply A, B, C, D but I don't want to do that. I want to
build the OtherArray by referencing MyArray and tacking D on to it.
How do I code the building of the OtherArray by using MyArray and D?
Thanks for your help. Otto
|