PDA

View Full Version : Appending arrays



mleary2001
02-22-2006, 01:16 PM
Is there an "append" operator or function in VBA for appending one array to another?

Thanks in advance,
Mike

XLGibbs
02-22-2006, 05:21 PM
I am not familiar with Mac per se, but not that I know of.

You can redeclare the dimensions of an array to include the dimensions of the other..

Say you have:

Dim myArray()
Dim lngCount as Long

lngCount = range("A1")

ReDim myArray(1 to lngCount)



Then you populate the redim'd array with potentially another array if needed



For x = 1 to UBound(MyArray)
MyArray(x) = 'something
Next x

mansky
02-26-2006, 10:03 AM
Hi Mike,
Short answer is no, not directly. In addition to XLGibbs post on ReDim, I'd add that you'll need to use the optional keyword "Preserve" in order to get the existing elements of your array saved during the ReDim process, otherwise, they'll get blown away.



ReDim Preserve A(10)

to re-dimension the array A to 10 elements, saving the existing values.


Ed