R
Ralph
I am trying to add values to a collection to display unique values. I have a
worksheet with comma separated values in a of column of cells. I am using the
Split function to loop through the values and add them to the Collection.
There are duplicate values in the string, I do not understand why they are
still added to the Collection.
Public Function RemoveDupes(c As Range) As String
Dim i As Integer
Dim itm
Dim strItems As String
Dim nStr() As String
Dim nColl As New Collection
nStr = Split(c, ",")
For i = 0 To UBound(nStr)
nColl.Add Item:=nStr(i)
Next
For Each itm In nColl
Debug.Print itm
strItems = strItems & itm & ","
Next
If Not Len(strItems) = 0 Then
RemoveDupes = Left(strItems, Len(strItems) - 1)
Else
RemoveDupes = ""
End If
Set nColl = Nothing
End Function
worksheet with comma separated values in a of column of cells. I am using the
Split function to loop through the values and add them to the Collection.
There are duplicate values in the string, I do not understand why they are
still added to the Collection.
Public Function RemoveDupes(c As Range) As String
Dim i As Integer
Dim itm
Dim strItems As String
Dim nStr() As String
Dim nColl As New Collection
nStr = Split(c, ",")
For i = 0 To UBound(nStr)
nColl.Add Item:=nStr(i)
Next
For Each itm In nColl
Debug.Print itm
strItems = strItems & itm & ","
Next
If Not Len(strItems) = 0 Then
RemoveDupes = Left(strItems, Len(strItems) - 1)
Else
RemoveDupes = ""
End If
Set nColl = Nothing
End Function