Let's say you want to find out how many unique values exist in a range that contains duplicate values. For example, if a column contains:

There are several ways to count unique values among duplicates.What do you want to do?



Count the number of unique values by using a filter

You can use the Advanced Filter dialog box to extract the unique values from a column of data and paste them to a new location. Then you can use the ROWS function to count the number of items in the new range.

  1. Select the range of cells, or make sure the active cell is in a table.

    Make sure the range of cells has a column heading.

  2. On the Data tab, in the Sort & Filter group, click Advanced.

    The Advanced Filter dialog box is displayed.

  3. Click Copy to another location.
  4. In the Copy to box, enter a cell reference.

    Alternatively, click Collapse Dialog button image to temporarily hide the dialog box, select a cell on the worksheet, and then press Expand Dialog button image.

  5. Select the Unique records only check box, and click OK.

    The unique values from the selected range are copied to the new location beginning with the cell you specified in the Copy to box.

  6. In the blank cell below the last cell in the range, enter the ROWS function. Use the range of unique values that you just copied as the argument, excluding the column heading. For example, if the range of unique values is B2:B45, then enter:

    =ROWS(B2:B45)

Count the number of unique values by using functions

Use the IF, SUM, FREQUENCY, MATCH, and LEN functions to do this task:

Example

The example may be easier to understand if you copy it to a blank worksheet.

How to copy an example

  1. Create a blank workbook or worksheet.
  2. Select the example in the Help topic.

    Note Do not select the row or column headers.

    selecting an example from helpSelecting an example from Help

  3. Press CTRL+C.
  4. In the worksheet, select cell A1, and press CTRL+V.
  5. To switch between viewing the results and viewing the formulas that return the results, press CTRL+` (grave accent), or on the Formulas tab, in the Formula Auditing group, click the Show Formulas button.
1
2
3
4
5
6
7
8
9
10
A B
Data Data
986 Buchanan
Dodsworth 563
67 789
235
Buchanan Dodsworth
689 789
Dodsworth 143
56 237
67 235
Formula Description (Result)
=SUM(IF(FREQUENCY(A2:A10,A2:A10)>0,1)) Count the number of unique number values in cells A2:A10, but do not count blank cells or text values (4)
=SUM(IF(FREQUENCY(MATCH(B2:B10,B2:B10,0),MATCH(B2:B10,B2:B10,0))>0,1)) Count the number of unique text and number values in cells B2:B10 (which must not contain blank cells) (7)
=SUM(IF(FREQUENCY(IF(LEN(A2:A10)>0,MATCH(A2:A10,A2:A10,0),""), IF(LEN(A2:A10)>0,MATCH(A2:A10,A2:A10,0),""))>0,1)) Count the number of unique text and number values in cells A2:A10, but do not count blank cells or text values (6)

Notes:

Function details