How to Find, Mark and Count Duplicates in Excel
To find duplicates in column A, use COUNTIF to count how many times each value appears in the range. Two or more means it is a duplicate.
Formula to use
=COUNTIF($A$2:$A$100, A2)>1TRUE if duplicated
Mark only the second and later copies
Lock only the start of the range ($A$2) and leave the end relative (A2). As you copy down, the range grows one row at a time, so the first copy stays blank and later copies are marked.
=IF(COUNTIF($A$2:A2, A2)>1, "Duplicate", "")"Duplicate" from the second occurrence
Highlight them with color
To see them without a formula, select the range and choose Home > Conditional Formatting > Highlight Cells Rules > Duplicate Values.
Find duplicates across several columns
To treat rows as duplicates only when both the name and the date of birth match, give COUNTIFS two conditions.
=COUNTIFS($A$2:$A$100, A2, $B$2:$B$100, B2)>1Duplicate when columns A and B both match
Count unique values
Add 1/(number of occurrences) for each value, and each group of equal values adds up to 1. A blank cell in the range causes a divide-by-zero error, so use it on a range without blanks.
=SUMPRODUCT(1/COUNTIF(A2:A10, A2:A10))Number of unique values
Common mistakes
"Liam" and "Liam " (with a trailing space) are counted as different values. Clean up spaces with TRIM before comparing.
If you only want to delete duplicates, Data > Remove Duplicates is faster. It changes the original, so work on a copy.
Try the functions used here
Change the arguments in the function playground and watch the calculation step by step.
- COUNTIF functionCounts the cells in a range that meet a condition.
- COUNTIFS functionCounts the rows that meet all of several conditions.
- IF functionReturns one value if a condition is true and another value if it is false.
- SUMPRODUCT functionMultiplies values in matching positions and adds the results.
- TRIM functionRemoves leading and trailing spaces and leaves single spaces between words.
FAQ
- Is it case-sensitive?
- No. COUNTIF counts "apple" and "APPLE" as the same value. Use EXACT to tell them apart.
- How do I compare with another sheet?
- If =COUNTIF(Sheet2!$A:$A, A2)>0, the value also exists on the other sheet.