Excel Productivity Guide
Useful Excel Tips | Keyboard Shortcuts | VBA Codes
Download this Free E-Book to take your excel skills to a whole next level using some smart Excel tactics.
10000+ Copies Already Downloaded
Let’s say you have a list of values where each value is entered more than once. And now, you want to count unique values from that list so that you can get the actual numbers of values which are there in the list.
For this, you need to use a method which will count a value only one time and ignore it’s all the other occurrences in the list. In Excel, you can use different methods to get a count of unique values. It depends that which type of values you have so that you can use the best method for it.
Here in this post, I will show you 5+1 different methods to count unique values. You can use these methods according to the type of the values you have.
Download this sample data file from here to follow along.
Table of Content
Using advanced filter is one of the easiest ways to check the count of unique values. And in this method, you don’t even need complex formulas.
Here we have a list of names and from this list, you need to count the number of unique names.
Please follow these simple step.
Now, you have a list of unique values and count as well. This method is simple and easy to follow. Ans I say you don’t have to write complex formulas for this.
In this method, you just have to refer to the list of the values and the formula will return the number of unique values. One thing which you have to do along with this formula is you need to enter it as an array. While entering the formula you need to use Ctrl + Shift + Enter.
And the formula is:
When you enter this formula as an array it will look something like this.
To understand this formula you need to break it down into three parts and just remember that we have entered this formula as an array and there are total 16 values in this list, not unique but total.
Ok, so look.
First of all, you have used COUNIF function to count the number of each value from 16. Here, COUNTIF returns values like below.
In the second part, you have divided all the values with 1 which returns value like this:
Important Point: Let’s say if a value is there in the list twice, then it will return 0.5 for both of the values so that in the end when you sum it, it becomes 1 and if a value is there for three times it will return 0.33 for each.
And, in the third part, you have simply used SUM function to sum all those values and you have a count of unique values.
This formula is quite powerful and it can help you to get the count in a single cell.
In the last method, you have used SUM and COUNTIF method. But, you can also use SUMPRODUCT instead of SUM. And, when you use SUMPRODUCT, you don’t need to use enter a formula as an array.
The formula you need to enter:
And, as an array function.
This formula exactly works in the same way as you have learned in above method, the difference just you have used SUMPRODUCT instead of SUM. SUMPRODUCT function can take an array without using Ctrl + Shift + Enter.
Now, let’s say you have a list of names in which you also have mobile numbers and you want to count unique values just from text values.
So, in this case, you can use below formula:
Enter this formula as an array.
After that, IF function will apply COUNTIF Function on all the text values and other values will remain blank.
And, when you use SUM function it will return the unique count of text values.
And, if you just want to count unique numbers from a list of values, you can use below formula.
Enter this formula as an array.
In this method, you have used IF function and ISNUMBER function. ISNUMBER function will first verify that all the values are number or not. And returns, TRUE or FALSE.
After that, IF function will apply COUNTIF Function on all the numeric values and other values will remain blank.
And, when you use SUM function it will return the unique count of numeric values.
Here I have VBA (UDF) code which can help you to count unique values without using any kind of formula. And for this code credit goes to ExcelTip.
Here is the code.
Function CountUnique(ListRange As Range) As Integer Dim CellValue As Variant Dim UniqueValues As New Collection Application.Volatile On Error Resume Next For Each CellValue In ListRange UniqueValues.Add CellValue, CStr(CellValue) ' add the unique item Next CountUnique = UniqueValues.Count End Function
Enter this function in your VBE by inserting a new module. And, after that fo to your worksheet and insert following formula.
Counting unique values can be useful for you while working with large data sets. Like the name list which you have used here had duplicate names. And after calculating unique numbers you get that you have 10 unique names in the list.
All the methods which you have learned here are super useful different situations. You can use anyone from these which you think is perfect for you.
If you ask me advanced filter and sumproduct is my favorites.
Now, tell me one thing. Which one is your favorite? Or, you have a different method. Please share with me in the comment box.
I would love to hear from you.