Flag first duplicate in a list

An excel formula to flag first duplicate in a list

Related Functions

Sponsored Link

 Flag first duplicate in a list
=IF(COUNTIF(A:A,A1)>1,IF(COUNTIF(A$1:A1,A1)=1,"x","xx"),"")

If you have a list with a number of duplicates, you can use a formula based on the COUNTIF function to flag the first occurence.

Optionally, you can also mark subsequent duplicates with a different marker.

In the example shown the formula in cell C4 is:

 
=IF(COUNTIF($B$4:$B$11,B4)>1,IF(COUNTIF($B$4:B4,B4)=1,"x","xx"),"")

This formula has been copied down the column, from C4 to C11.

How this formula works

At the core, this is a COUNTIF formula, wrapped in an IF statement.

Working from the outside in, IF first checks to see if the first value in the list (B4) in this case, exists more than once in the list:

 
=IF(COUNTIF($B$4:$B$11,B4)>1

If so, we run another COUNTIF, inside another IF.

If the value doesn't exist, the IF statement returns "" (an empty string).

The 2nd IF / COUNTIF does the main work and looks like this:

 
IF(COUNTIF($B$4:B4,B4)=1,"x","xx")

This part of the formula uses a mixed reference ($B$4:B4) that expands as the formula is copied down the column. (The first B4 in the range is absolute (locked), the second is relative, so it changes as the formula is copied down the list).

Remember that this part of the formula is only running if the COUNTIF said the value appears more than once in the list.

So, at each row, the formula checks the count inside the mixed reference. If it's 1, we mark the duplicate with "x", since it's the first one we've seen. If it's not 1, we know it must be a subsequent dup, and we mark the duplicate with "xx"

Of course, you can customize these markers any way you like.

If you don't want to mark subsequent dups at all, just use "" instead of "xx".

Sponsored Link

0 votes. 0 / 5