Count unique values in a list (some delimited)

No Good At This

New Member
Joined
Feb 17, 2014
Messages
5
Hi,

I hope this makes sense, but I need some VBA to count all of the unique items in a list such as:

1
2
3
4,5,6
3
2
1,2,3

As in, some cells will only contain one number but others will contain a number of them in a single cell.

Any help would be greatly appreciated

Thanks
 

Excel Facts

Save Often
If you start asking yourself if now is a good time to save your Excel workbook, the answer is Yes
Here's a UDF you can use on the worksheet as shown below the function. Assumes that your delimiter is a comma and your data are numbers:
Code:
Function CountUniques(R As Range) As Long
Dim d As Object, c As Range, vA As Variant
Set d = CreateObject("Scripting.dictionary")
d.RemoveAll
For Each c In R
    If InStr(c.Value, ",") > 0 Then
        vA = Split(c.Value, ",")
        For i = LBound(vA) To UBound(vA)
            If Not d.exists(Val(vA(i))) Then
                ct = ct + 1
                d.Add Val(vA(i)), ct
            End If
        Next i
    Else
        If Not d.exists(c.Value) Then
            ct = ct + 1
            d.Add c.Value, ct
        End If
    End If
Next c
CountUniques = d.Count
End Function
Excel Workbook
ABC
116
22
33
44,5,6
53
62
71,2,3
Sheet4
 
Upvote 0

Forum statistics

Threads
1,221,525
Messages
6,160,329
Members
451,637
Latest member
hvp2262

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top