Digita
03-17-2009, 10:33 PM
Hi guys,
I got stuck in a problem which initially sounds simple but is driving me nuts. Basically, I would like to count the occurences of all unique elements in an array which consists of 163, 357, 163, 357, 163, 357, 323. I put the unique numbers in a kinda of helper array and loop all the numbers in the original array through it and count the ones that are the same.
Here is my script and the part that does not work is marked in red.
abc = Array(163, 357, 163, 357, 163, 357, 323)
For Each cel In abc
If unik = Empty Then
unik = cel
ElseIf InStr(1, unik, cel, 1) = 0 Then unik = unik & "," & cel
End If
Next
arr = Split(unik, ",")
For j = 0 To UBound(arr, 1)
For i = 0 To UBound(abc, 1)
Debug.Print arr(j) & " - " & abc(i) & " - " & IIf(arr(j) = abc(i), "Equal", "")
If arr(j) = abc(i) Then iCnt = iCnt + 1
Next i
iCnt = 0 'Reset counter
Next j
Thanks in advance for your generous help.
Regards
kp
I got stuck in a problem which initially sounds simple but is driving me nuts. Basically, I would like to count the occurences of all unique elements in an array which consists of 163, 357, 163, 357, 163, 357, 323. I put the unique numbers in a kinda of helper array and loop all the numbers in the original array through it and count the ones that are the same.
Here is my script and the part that does not work is marked in red.
abc = Array(163, 357, 163, 357, 163, 357, 323)
For Each cel In abc
If unik = Empty Then
unik = cel
ElseIf InStr(1, unik, cel, 1) = 0 Then unik = unik & "," & cel
End If
Next
arr = Split(unik, ",")
For j = 0 To UBound(arr, 1)
For i = 0 To UBound(abc, 1)
Debug.Print arr(j) & " - " & abc(i) & " - " & IIf(arr(j) = abc(i), "Equal", "")
If arr(j) = abc(i) Then iCnt = iCnt + 1
Next i
iCnt = 0 'Reset counter
Next j
Thanks in advance for your generous help.
Regards
kp