User Rating: 5 / 5

Count Number of Unique Values, with Excel Functions
Remove Duplicates or Create a List of Unique Records Using Advanced Data Filter
Remove Duplicates in a range, using "Remove duplicates" button in Data Tools
--------------------------------------------------------------------------------------------------------------------------

Remove Duplicates or Create a List of Unique Records in Excel

Create a List of Unique Records (Using Excel Formula):

1. Column B contains a list of names, including duplicates and a List of Unique Names is returned in column C, with the creation of the helper column (column A). (refer Table 1)

2. Create a helper Column towards the left viz. column A. Enter 1 in the first cell corresponding to the first name in column B.

3. Enter the formula =IF(COUNTIF( \$B\$2:B3,B3)=1, A2+1, A2) in cell A3 and copy it down column A. You will notice that if the number increments from the previous/upper cell in column A, then the corresponding record in column B is unique. The formula counts the number of names in column B till the current row, and increments the number in column A (from the upper cell) if the name has occurred only once till that row, else returns the same number as in the upper cell (in column A).

4.  =IFERROR( VLOOKUP(ROW()-1, \$A\$2:\$B\$16,2, FALSE),"") -> Enter this formula in cell C2 and copy it down column C. The formula does a vlookup of running values starting from 1, searches for corresponding results in column B, and returns unique values in column C.

5. You can delete the helper column viz. column A, as its purpose has been served by now.

Explaining the formula in cell A3 (refer Table 1):  =IF(COUNTIF(\$B\$2:B3,B3)=1,A2+1,A2)

=COUNTIF(\$B\$2:B3,B3)  [Formula Break]

Counts the number of times the value in cell B3 (viz. Paul Spencer) appears in column B, till the current row (viz. in range \$B\$2:B3).

Please note the use of absolute and relative references for the range \$B\$2:B3. The absolute reference (\$B\$2) is used to start the search from the first cell in the range/column. The relative reference (B3) is used to keep the last cell in the range dynamic, till the current row.

=IF(COUNTIF(\$B\$2:B3,B3)=1, A2+1, A2)  [Formula]

If COUNTIF returns 1, which means the value in cell B3 is unique in column B till the current row, then formula increments cell A3 by 1 from cell A2, else cell A3 value remains same as cellA2.

This indicates that if the number in cell A3 increments by 1 from cell A2, then the corresponding record in column B (ie. cell B3) is unique till now.

Explaining the formula in cell C2 (refer Table 2):  =IFERROR(VLOOKUP(ROW()-1, \$A\$2:\$B\$16, 2, FALSE), "")

=ROW()-1  [Formula Break]

Row() returns the number of the current row. ROW()-1 is used (in cell C2) to start from number 1, which corresponds to the value in first cell in column A which is 1. This generates running numbers as you move down the column viz. number 2 in cell C3, number 3 in cell C4, and so on.

=(VLOOKUP(ROW()-1, \$A\$2:\$B\$16, 2, FALSE)  [Formula Break]

This formula does a vlookup of each running number in column A, and returns matching names in column no 2 (which is column B), and these are unique names which appear in column C (where this formula is entered).

Vlookup of a number (viz. vlookup of number 3) will return the first occurrence of the matching value in column B (ie. Jim Clapton in cell B4) and ignore the subsequent occurrences (ie. John in cell B5). This is how the unique names appear in column C.

=IFERROR(VLOOKUP( ROW()-1, \$A\$2:\$B\$16,2, FALSE), "")  [Formula]

If the Vlookup formula returns an error (viz. #N/A), the formula will return a blank ("") value.