kylefoley76
Well-known Member
- Joined
- Mar 1, 2010
- Messages
- 1,553
I have a very tough time with the redim function and the multi-dimensional arrays. I'm trying to merge two multi-dimensional arrays into one. I know that the second dimension of each array will always be 2, but the first dimension will change. When I use the redim function I do not get an error message but it erases everything that was in the first array in the first place. When I use redim preserve I get a subscript out of range. Help.
Code:
Function merge_arrays2(first_array As Variant, sec_array As Variant) As Variant
Dim i As Integer, j As Integer, m As Integer
m = UBound(sec_array)
j = UBound(first_array)
ReDim first_array(m + j, 2)
For i = 1 To UBound(sec_array)
j = j + 1
first_array(j, 1) = sec_array(i, 1)
first_array(j, 2) = sec_array(i, 2)
Next
merge_arrays2 = first_array
End Function