Please Note: This article is written for users of the following Microsoft Excel versions: 2007, 2010, 2013, and 2016. If you are using an earlier version (Excel 2003 or earlier), this tip may not work for you. For a version of this tip written specifically for earlier versions of Excel, click here: Getting a Count of Unique Names.

Getting a Count of Unique Names

by Allen Wyatt
(last updated June 11, 2018)


John has a worksheet that he uses for registration of attendees at a conference. Column A has a list of each person attending, and column B has the company represented by each attendee. Each company can have multiple people attend. John can easily figure out how many individuals are coming to the conference; it is simply the number of rows in column A (minus any header rows). The more difficult task is to determine how many companies are going to be represented at the conference.

There are a couple of ways to determine the desired count. First, if there are no blank cells in column B, you can use an array formula (entered by Ctrl+Shift+Enter) such as the following:


If there are blanks in the range (B2:B50 in this case), then the array formula will return a #DIV/0! error. If that case, the array formula needs to be changed to the following:


If you prefer to not use an array formula, you can add regular formulas to column C to do the count. First, sort the table of data by the contents of column B. That way the data will be in company order. Then add a formula such as the following to cell C2 (assuming you have a header in row 1):


Copy the formula down through all the rest of the cells in column C, and then do a sum on the column. The sum represents the number of unique companies attending, since a 1 only appears in column C when the company name changes.

Of course, if you need to find the names of all the companies represented at the conference, you can use Excel's filtering capabilities. Follow these steps:

  1. Sort the data by column B, the company names.
  2. Select all the cells containing data (including the header cell) in column B.
  3. Display the Data tab of the ribbon.
  4. Click the Advanced tool, in the Sort & Filter group. Excel displays the Advanced Filter dialog box. (See Figure 1.)
  5. Figure 1. The Advanced Filter dialog box.

  6. Make sure the Copy to Another Location radio button is selected.
  7. Make sure the Unique Records Only check box is selected.
  8. With the insertion point in the Copy To box, click on a blank cell, such as E1. (This is where the list of companies will be copied to.)
  9. Click OK. Excel copies the unique company names from the original list to column E.

You now can easily see how many companies are being represented, along with who those companies are.

ExcelTips is your source for cost-effective Microsoft Excel training. This tip (7562) applies to Microsoft Excel 2007, 2010, 2013, and 2016. You can find a version of this tip for the older menu interface of Excel here: Getting a Count of Unique Names.

Author Bio

Allen Wyatt

With more than 50 non-fiction books and numerous magazine articles to his credit, Allen Wyatt is an internationally recognized author. He is president of Sharon Parq Associates, a computer and publishing services company. ...


Changing Toolbar Location

Toolbars don't need to be tethered to the top of your program window. Although they are right at home there, you may want ...

Discover More

Colorizing Charts

Need to change the color of different parts of your chart? It's easy to do when you apply the technique described in this ...

Discover More

Adding a User Account

Windows allows you to set up individual user accounts in case there are multiple people using the same computer. Here's ...

Discover More

Save Time and Supercharge Excel! Automate virtually any routine task and save yourself hours, days, maybe even weeks. Then, learn how to make Excel do things you thought were simply impossible! Mastering advanced Excel macros has never been easier. Check out Excel 2010 VBA and Macros today!

More ExcelTips (ribbon)

Setting Up Custom AutoFiltering

The filtering capabilities of Excel are very helpful when you are working with large sets of data. You can create a ...

Discover More

Dealing with Text Length Limits and AutoFilter Drop-Down Lists

Excel has some built-in limits on what you can do with the program. When you run into those limits, it can be frustrating ...

Discover More

Using AutoFiltering

Excel's AutoFilter tool is a great way to make a long list of items much more manageable. This tip explains how to set up ...

Discover More

FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."

View most recent newsletter.


If you would like to add an image to your comment (not an avatar, but an image to help in making the point of your comment), include the characters [{fig}] in your comment text. You’ll be prompted to upload your image when you submit the comment. Maximum image size is 6Mpixels. Images larger than 600px wide or 1000px tall will be reduced. Up to three images may be included in a comment. All images are subject to review. Commenting privileges may be curtailed if inappropriate images are posted.

What is five minus 4?

2017-08-08 06:30:29

Harish Gupta

Hi All, I was able to perform with another array formula[assuming data is sorted]. The formula would be =SUM(IF(B2:B50<>B3:B51,1,0))

2017-08-07 12:33:56


Thanks Allen for this Excel Tip on finding out Unique values dynamically with a single formula.
If there are blank cells in a Column, As you said Formula "=SUM(1/COUNTIF(B2:B50,B2:B50))" would return an error.
I used IFERROR in this formula to ignore the error values and it worked for me.
The formula is "=SUM(IFERROR(1/COUNTIF(B2:B50,B2:B50),0))".
I hope this is right and a simple one.

2017-07-31 08:53:33

Pete Zicari

Between James Cameron's explanation of the formula's logic and Mickey's image, I think I see how it works. As an array formula, the countif part returns an array of the counts of each unique element. But a count of the elements is required, not a list.
Taking the reciprocal of each element of that second array means that no matter how many instances of a unique element there are, the sum of the reciprocals will always be 1.
Adding the result gets you the count of the unique elements.

The missing information, for me, was understanding that countif(A1:A13,A1:A13) yields an array with the count of each of the uniques in each of the result rows. It follows that adding up the reciprocals would yield the true count, but frankly, that bit of mathematical cleverness would never have occurred to me. I guess that's why some of us launch rockets and some of us count beans. Thanks to both of you.

2017-07-29 04:00:29

Michael (Micky) Avidan

@Pete Zicari,
Can the following picture be considered as "Counter-intuitive than....." ?
(see Figure 1 below)
Michael (Micky) Avidan
“Microsoft® Answers" - Wiki author & Forums Moderator
“Microsoft®” Excel MVP – Excel (2009-2018)

Figure 1. 

2017-07-28 09:54:10

Pete Zicari

Allen, I'm very interested in the possibilities of array formulas, but figuring out why things like the one above makes my head hurt. I mean, if there's something more counter-intuitive than:
... I would be surprised to see it. And yet it worked exactly as advertised for me. (Excel 2016 for Mac). Where would I go to figure this out?

-- and thanks.

2017-07-28 09:26:11

Lee Webber

Why not just do a quick Pivot Table? It will quickly tell you how many unique companies and users are attending? Just use the Distinct Count feature by adding the data to a data model.

2017-07-28 04:49:46

Eliz Ward

A quick pivot table would also do the trick nicely.

2013-07-28 14:01:48



I have one doubt please help me

1 cell I put "sudheersudheer" like this I want only "ee" another cell

2013-07-24 12:00:05


Actually reading again, I realize that I just repeated what kdp said, but took longer to get to the point.

If you do follow the specifics of my example it would be ...
=COUNTIF($A$3:$A$5563,L26)<- not L25 as you copy down the column.

2013-07-24 11:53:18

Steve Nadel

Like Gteg, I have tried array formulas, but have to work with them a whole lot more to get comfortable.

I might be slow, but I couldn't get the advance filter to work no matter what. My guess is I'm not fully understanding what goes into the "list range" and what goes into the criteria range".

This is how I have handled this issue for years. Maybe it is so simple that I am missing things that people are trying to achieve.

If I have a large list of data and I want to count how many of each unique group are in a specific column are there, I run a simple =COUNTIF on a table that looks like a =VLOOKUP table.

I start a table listing all the unique criteria (i.e. companies) in the first column. I do this on the right side of the data (skipping a column for future sorting of course).

I build a formula in the cell to the right of the first example
=countif(entire data range as an absolute range, unique group to the immediate left side.) Then copy that formula down for the other unique group. i.e.

My apologies for anyone who is not familiar with VLOOKUP tables.

2013-07-23 08:25:04


Why not just copy the column of company's to another tab then use the Remove Duplicates feature and follow up with the count formula?

2013-07-22 07:56:12


I would use a pivot table to both sort and count.

2013-07-21 23:31:33


Dear Allen Wyatt,
It is great. Very useful.
Thank you.

2013-07-21 23:23:26

James Cameron


If you run the formula across a small volume of data containing some duplications you will soon see how it works.

In essence,

(1) assume you create a list of names in which one particular name appears n times;

(2) on each occasion that the formula finds that name in the list the Countif portion of the formula will calcuate a value of n;

(3) The reciprocal portion of the formual will convert each value of n to 1/n;

(4) the Sum portion of the formual will add up each of these fractions, ie n*1/n, which results in a value of 1 for that name;

(5) As each specific name results in a Countif value of 1 (regardless of how often it is repeated), the final value of the Sum function gives the total number of specific names in the list.

2013-07-21 04:13:47

Andrew Gilmour

newdoverman's solution is elegant and well thought out.
Gtegs comments are relevant and I have noticed that whilst solutions are offered up there is no detailed explanation as to why they work which is very frustrating as it does not engender greater understanding. A little more detail in terms of why thinks work would be a great help make this site more user-friendly.

Great site anyway.

2013-07-20 09:14:59


In addition to the above, this formula will count down the column assigning each unique company a number in order. The last company will have the total number of companies.


2013-07-20 08:31:09


If you can alter the list (e.g. sort), then wouldn't copying the list to a temporary sheet and using the built-in Remove Duplicates feature in the Data tab, or generating a quick Pivot Table be just as easy?

I did like the array formulas... I'll have to look into those more... not sure I understand the 1/ portion of thus one.

This Site

Got a version of Excel that uses the ribbon interface (Excel 2007 or later)? This site is for you! If you use an earlier version of Excel, visit our ExcelTips site focusing on the menu interface.

Newest Tips

FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."

(Your e-mail address is not shared with anyone, ever.)

View the most recent newsletter.