Thread
:
union array
View Single Post
#
5
Posted to microsoft.public.excel.programming
Tushar Mehta
external usenet poster
Posts: 1,071
union array
Given that I screwed up once, the likelihood that I would post untested code
is...Zero!
I tested the code. It works. w contains the correct result.
--
Regards,
Tushar Mehta
www.tushar-mehta.com
Excel, PowerPoint, and VBA add-ins, tutorials
Custom MS Office productivity solutions
In article ,
says...
not correct this function
test the testunion is result empty !!!
Marina
Well, I was kinda surprised that a search of the google.com archives of
the XL NGs didn't show up anything. So, I put something together:
Option Explicit
Option Base 0
Function VBAUnion(ParamArray Arr())
Dim x As Collection, I As Integer, J As Integer, Rslt
Set x = New Collection
For I = LBound(Arr) To UBound(Arr)
If IsArray(Arr(I)) Then 'handles only 1D array
For J = LBound(Arr(I)) To UBound(Arr(I))
On Error Resume Next
x.Add Arr(I)(J), CStr(Arr(I)(J))
On Error GoTo 0
Next J
Else
On Error Resume Next
x.Add Arr(I), CStr(Arr(I))
On Error GoTo 0
End If
Next I
ReDim Rslt(x.Count - 1)
For I = LBound(Rslt) To UBound(Rslt)
Rslt(I) = x.Item(I + 1)
Next I
VBAUnion = Rslt
End Function
Sub testUnion()
Dim x, y, z, w
x = Array("a", "b")
y = Array(1, "b")
z = Array(1, 2, 3)
w = VBAUnion(x, y, z)
End Sub
--
Regards,
Tushar Mehta
www.tushar-mehta.com
Excel, PowerPoint, and VBA add-ins, tutorials
Custom MS Office productivity solutions
In article ,
says...
how I union this 3 arrays ?
example:
A = array("mary", "john")
B = array("Peter")
C = array("Roger")
How to do?
D = A + B + C
thanks
Marina
Reply With Quote
Tushar Mehta
View Public Profile
Find all posts by Tushar Mehta