First add a reference to "Microsoft Scripting Runtime"
then try the code (pass the array to the function)
...(found from google groups)
VB Code:
Sub CountDuplicates(A As Variant) Dim D As Dictionary Dim i As Long, key As Variant Set D = New Dictionary For i = LBound(A) To UBound(A) key = A(i) If D.Exists(key) Then D.Item(key) = D.Item(key) + 1 Else D.Add key, 1 End If Next i i = 0 For Each key In D.Keys If key <> "" Then MsgBox key & D.Item(key) End If i = i + 1 Next key End Sub
Hope this helps!




Reply With Quote