unique values in an array
Dana DeLouis wrote:
Would something like this work?
Sub TestIt()
Dim V
V = Array("a", "b", "c", "b", "d", "c", "e")
V = Unique(V)
End Sub
Function Unique(V) As Variant
Dim d As Object
Dim Obj
Set d = CreateObject("Scripting.Dictionary")
On Error Resume Next
For Each Obj In V
d.Add Obj, 1
Next Obj
Unique = d.Keys
End Function
Not if V is of type String() as stated by the OP. E.g., the following
doesn't work:
Sub TestIt()
Dim V() As String
ReDim V(1 To 7)
V(1) = "a"
V(2) = "b"
V(3) = "c"
V(4) = "b"
V(5) = "d"
V(6) = "c"
V(7) = "e"
V = Unique(V) '<---Type mismatch error message
End Sub
|