Merges two 1-dimension arrays and return an array
Both should be 1 dimensional arrays.
Code has commented codes with example of how to treat arrays from Excel sheet range objects.
Bottom line, Arrays created using Range object in Excel (or Cell object) are always 2 dimensions arrays, even if they were referred to 1 dimension range.
Function merge2Arrays(Arr1, Arr2)
Dim returnThis()
Dim len1 , len2 , lenRe , counter
len1 = UBound(Arr1)
len2 = UBound(Arr2)
lenRe = len1 + len2
ReDim returnThis(1 To lenRe)
counter = 1
Do While counter <= len1 ' get first array in returnThis
' returnThis(counter) = Arr1(counter, 1) ' < < < < Use this if arrays were created in Excel using Range object.
returnThis(counter) = Arr1(counter)
counter = counter + 1
Loop
Do While counter <= lenRe 'get the second array in returnThis
' returnThis(counter) = Arr2(counter - len1, 1) ' < < < < Use this if arrays were created in Excel using Range object.
returnThis(counter) = Arr2(counter - len1)
counter = counter + 1
Loop
merge2Arrays = returnThis
End Function
Dim returnThis()
Dim len1 , len2 , lenRe , counter
len1 = UBound(Arr1)
len2 = UBound(Arr2)
lenRe = len1 + len2
ReDim returnThis(1 To lenRe)
counter = 1
Do While counter <= len1 ' get first array in returnThis
' returnThis(counter) = Arr1(counter, 1) ' < < < < Use this if arrays were created in Excel using Range object.
returnThis(counter) = Arr1(counter)
counter = counter + 1
Loop
Do While counter <= lenRe 'get the second array in returnThis
' returnThis(counter) = Arr2(counter - len1, 1) ' < < < < Use this if arrays were created in Excel using Range object.
returnThis(counter) = Arr2(counter - len1)
counter = counter + 1
Loop
merge2Arrays = returnThis
End Function
ByRef Arr1() As Variant, Arr2() As Variant
Views 135
Downloads 55
CodeID
DB ID
ANmarAmdeen
602
Revisions
v2.0
Tuesday
September
21
2021