Unique numbers in array

K

Kalle

Hi

I have an array that contains about 200 numbers and I need to check so
the array onley contains unique numbers. If it contains double I want to
remove them.

How do I do that in an easy way?

Thanks in advance


*** Sent via Developersdex http://www.developersdex.com ***
 
H

Harald Staff

Hi

One quick and dirty way:

Sub test()
MsgBox Uniques("1,2,3,3,3,4,5,4,3,56,12,56", ",")
End Sub

Function Uniques(strData As String, _
strDelimiter As String) As String
Dim C As Collection
Dim AR() As String
Dim i As Long
AR = Split(strData, strDelimiter)
Uniques = ""
Set C = New Collection
On Error Resume Next
For i = LBound(AR) To UBound(AR)
C.Add AR(i), AR(i)
Next
For i = 1 To C.Count
Uniques = Uniques & C(i) & ","
Next
Uniques = Left$(Uniques, Len(Uniques) - 1)
Set C = Nothing
End Function


HTH. Best wishes Harald
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top