wackywoo105
Registered User.
- Local time
- Today, 04:35
- Joined
- Mar 14, 2014
- Messages
- 203
I want to remove duplicates from an array. I came up with my own method before finding one, which involved setting duplicate entries 0 and just ignoring them.
Mine was:
The above is messy so I searched and found the function below:
My concern is my method shows a count of 960 but the found method shows a count of 959. No "0"s should be included in my function count, so they should both show the same number of individual entries. Can anyone tell me why the difference of 1?
Mine was:
Code:
NumberList() = Split(NumbersString, ",")
For x = 0 To UBound(NumberList())
For j = 0 To UBound(NumberList())
If Not x = j Then
If NumberList(x) Like NumberList(j) Then NumberList(j) = 0
End If
Next j
Next x
Dim countB As Integer
countB = 0
For x = 0 To UBound(NumberList())
If Not NumberList(x) Like "0" Then countB = countB + 1
Next x
MsgBox countB
The above is messy so I searched and found the function below:
Code:
Dim DeDupeArray() As Variant
Dim oDict As Object, i As Long
Set oDict = CreateObject("Scripting.Dictionary")
For i = LBound(NumberList) To UBound(NumberList)
oDict(NumberList(i)) = True
Next
DeDupeArray = oDict.keys()
MsgBox UBound(DeDupeArray)
My concern is my method shows a count of 960 but the found method shows a count of 959. No "0"s should be included in my function count, so they should both show the same number of individual entries. Can anyone tell me why the difference of 1?
Last edited: