Funciton that Combines 3 or more Arrays

G

Guest

Came across this function to combine arrays in this newsgroup (Sorry can't
rememer who posted it). It takes two arrays as arguments and returns 1
combined array. Works very well. Does anyone know if there is similar
function around for 3 or more arrays. I was going build in the third array
but realised I may need more than 3. Thanks and sorry for not crediting the
author of the function.


Function ArrayUnion(ByVal va1 As Variant, ByVal va2 As Variant) As Variant
Dim i As Long, Upper As Long
If TypeName(va1) = "Empty" Then
va1 = va2
Else
Upper = UBound(va1)
If LBound(va2) = 0 Then Upper = Upper + 1
ReDim Preserve va1(LBound(va1) To UBound(va1) + UBound(va2) -
LBound(va2) + 1)
For i = LBound(va2) To UBound(va2)
va1(Upper + i) = va2(i)
Next i
End If
ArrayUnion = va1
End Function

Thanks

EM
 
G

Guest

Can't you just call the function twice like this:

ThreeArrays = ArrayUnion(ArrayUnion(Array1, Array2), Array3)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top