Thread: union array
View Single Post
  #15   Report Post  
Posted to microsoft.public.excel.programming
Tushar Mehta Tushar Mehta is offline
external usenet poster
 
Posts: 1,071
Default union array

Nice touch, Dana, using the Scripting.Dictionary object.

--
Regards,

Tushar Mehta
www.tushar-mehta.com
Excel, PowerPoint, and VBA add-ins, tutorials
Custom MS Office productivity solutions

In article ,
says...
I like to use a slight variation to Tushar's excellent code example. This
small example does not have much error checking thou.

Function VBA_Union(ParamArray V())
Dim J, K
Dim Sd
Const Dummy As Byte = 0

Set Sd = CreateObject("Scripting.Dictionary")

On Error Resume Next
For J = 0 To UBound(V)
For K = 0 To UBound(V(J))
Sd.Add V(J)(K), Dummy
Next K
Next J
VBA_Union = Sd.Keys
End Function

Sub TestIt()
Dim x, y, z, w
x = Array("a", "b", 1)
y = Array(1, "b")
z = Array(1, 2, 3)
w = VBA_Union(x, y, z)
End Sub

Certain math programs by default have the function 'Union' remove all
duplicate items. (and will Sort the results also).