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

# Getting a Count of Unique Names

by Allen Wyatt
(last updated February 20, 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:

```=SUM(1/COUNTIF(B2:B50,B2:B50))
```

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:

```=SUM(IF(FREQUENCY(IF(LEN(B2:B50)>0,MATCH(B2:B50,B1:B50,0),
""),IF(LEN(B2:B50)>0,MATCH(B2:B50,B2:B50,0),""))>0,1))
```

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):

```=IF(B2<>B3,1,0)
```

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 companies change.

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. Choose Filter from the Data menu, then choose Advanced Filter. Excel displays the Advanced Filter dialog box. (See Figure 1.)
4. Figure 1. The Advanced Filter dialog box.

5. Make sure the Copy to Another Location radio button is selected.
6. Make sure the Unique Records Only check box is selected.
7. 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.)
8. 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 (3105) applies to Microsoft Excel 97, 2000, 2002, and 2003. You can find a version of this tip for the ribbon interface of Excel (Excel 2007 and later) 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. ...

##### MORE FROM ALLEN

Getting Rid of Mail Merge Section Breaks

When you create a group of documents from a merge file, Word normally inserts section breaks between iterations of the ...

Discover More

Moving Table Rows Quickly

One of the most esoteric shortcuts available in Word is one that allows you to move table rows, either within a table or ...

Discover More

Clearing the Undo Stack in a Macro

When writing a macro, you may need a way to clear the undo stack. This can be done with a single command, as described in ...

Discover More

Program Successfully in Excel! John Walkenbach's name is synonymous with excellence in deciphering complex technical topics. With this comprehensive guide, "Mr. Spreadsheet" shows how to maximize your Excel experience using professional spreadsheet application development tips from his own personal bookshelf. Check out Excel 2013 Power Programming with VBA today!

Automatically Numbering Rows

Adding row numbers to a column of your worksheet is easy; you just need to use a formula to do it. Here's a quick look at ...

Discover More

Averaging Values for a Given Month and Year

Excel is often used to analyze data collected over time. In doing the analysis, you may want to only look at data ...

Discover More

Extracting Street Numbers from an Address

Want to know how to move pieces of information contained in one cell into individual cells? This option exists in using ...

Discover More
##### Subscribe

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

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 more than 3?

2016-05-03 07:22:07

Shreyas MJ

Hello,

I have a invoice data for three years i want to do comparision for the uniques vendor names added month on month for a particular year and also would like to know what are the excisting vendors month on month.

Please let me know how can this be achieved.

Thanks
Shreyas

2015-09-26 06:39:11

Ramesh.P.S

How can i count Absent,Present and half day value as '0','1'and '0.5' respectively in a single cell. for the preparation of Salary sheet from daily report.....

2015-02-20 18:12:10

TheQuaker

=(COUNTIF(\$B\$2:\$B\$8,B2)/COUNTIF(\$B\$2:\$B\$8,B2))-SUMIF(\$B\$1:B1,B2,\$C\$1:C1)

Returns error on blank cells; may or may not be desirable.

2014-07-11 03:26:54

Steven Marzuola

I used the Sort in-place method, just to see something, and then deleted the values in those cells. Later I realized that some of the rows remained hidden. How can I unhide those rows?

2014-06-22 03:18:26

Kuttan

I have one sheet with a family details.
for example, employee, has 2 wife, three son and 3 daughter, can you please help me how to count

2013-07-05 10:11:49

Michael (micky) Avidan

@Scott Renz,
With all due respect - there are numerous solutions, that involves helper Rows/Columns/Sheets.

My "Moto" (and you may protest against it) is to use NO helper elements and keep formulas as simple as possible.

Michael Avidan
“Microsoft®” MVP – Excel
ISRAEL

2013-07-01 11:23:03

Scott Renz

I would just copy the column of company names to a new sheet and click on "Remove Duplicates" in the "Data Tools" tab under "Data." Then it is just a simple count of the cells in the column with data.

2013-06-29 10:56:29

Michael (micky) Avidan

@Steve & Esskay,

As far as I remember the issue was presenting ONE(!) figure as the count of the UNIQUE values in a range.

With all due respect - a PT is not one of the common solutions for that task.

On answer requests the use of ONE cell (Only a SINGLE Cell) not a Helper column neither a PT.

I rest my case.

Michael Avidan
“Microsoft®” MVP – Excel
ISRAEL

2013-06-29 10:46:29

Michael (micky) Avidan

@Roan,
I never heard someone offering a presentation of 49(!) formulas in 49 cells in order to count the Unique Values.
(Would you consider that as a decent suggestions if the range was B2:B634587 ?
Farther more - no one mentioned (at least I didn't) anything about the need to sort the list.
Above all that - try to "empty" some cells in the range and let me know if you consider "blanks as "unique" values (because your suggested procedure counts them as such!)

Michael Avidan
“Microsoft®” MVP – Excel
ISRAEL

2013-06-29 09:22:33

Steve

A pivot table would do this quickly ... point and click, no formula needed.

2013-06-29 07:36:58

Esskay

Or you could just throw the data into a pivot table.

2013-06-29 05:48:45

Roan

My apologies, it should be

=IF(COUNTIF(\$B\$1:B2,B2)>1,0,1)

2013-06-29 05:42:36

Roan

If you don't want to use an array formula and prefer not to sort the list first, then you can use

=IF(COUNTIF(\$B\$1:B1,B2)>1,0,1)

Drag it down to row 50 and count column B. For those who would like to know why it works: the crux is that as you drag the formula down, the countif range expands because the part after the colon does not have the \$ signs (ie. not absolutely referenced).

2013-06-29 05:37:23

Michael (micky) Avidan

For avoiding he formula from referring to/counting empty cells - there is no need for such a "monster" Array formula.

Here is a much simpler/shorter one:

=SUM((B2:B50<>"")/(COUNTIF(B2:B50,B2:B50)+(B2:B50="")))

Michael Avidan
“Microsoft®” MVP – Excel
ISRAEL

##### This Site

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