Unique value - macro

gbell3587

Board Regular
Joined
Jan 30, 2011
Messages
117
Hi

I need to count the number of unique values on my worksheet. I have a formula that works fine when i enter the start and end point

Code:
=SUM(IF(FREQUENCY(MATCH(A1:A10,A1:A10,0),MATCH(A1:A10,A1:A10,0))>0,1))

I need to find them in an entire column a:a and this doesnt work. Also, i would ideally like to have this as a macro using application.worksheetfunction syntax but dont know how to do this.

Can anyone help?

Thanks
Graham
 

Excel Facts

Can a formula spear through sheets?
Use =SUM(January:December!E7) to sum E7 on all of the sheets from January through December
One way:

Code:
Function CountUnique(r As Range) As Long
    Dim sAdr As String
    Dim sFrm As String
 
    sAdr = Intersect(r.Worksheet.UsedRange, r.Areas(1)).Address
    sFrm = "sumproduct((" & sAdr & " <> """")/countif(" & sAdr & ", " & sAdr & " & """"))"
    CountUnique = r.Worksheet.Evaluate(sFrm)
End Function

E.g., =CountUnique(A:B)
 
Upvote 0
As a non VBA alternative,

Code:
{=sum(1/countif(A1:A10,A1:10))}

You could replace A1:A10 with a dynamic named range.
 
Upvote 0

Forum statistics

Threads
1,224,522
Messages
6,179,297
Members
452,903
Latest member
Knuddeluff

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