How-to recipes · Formatting
How to highlight duplicates in Excel
Colour repeated values with conditional formatting: the built-in Duplicate Values rule, a COUNTIF rule for second occurrences only, and whole rows.
Before you delete anything, you usually want to see the duplicates: which invoice numbers were entered twice, which employee ID appears in two rows, which email registered three times. Conditional formatting can colour them automatically, and the colour disappears as soon as the duplicate is fixed. This recipe covers the quick built-in rule, a formula rule that marks only the extra copies, highlighting entire rows, and a formula that lists the duplicate values.
The example data
Invoice numbers in A2:A9. INV-1002 appears three times and INV-1003 twice; everything else is unique.
The quick way (all versions)
- Select A2:A9 (only the data, not the header).
- Go to Home > Conditional Formatting > Highlight Cells Rules > Duplicate Values.
- Leave the first box on Duplicate (choose Unique to colour the single values instead) and pick a format, for example Light Red Fill with Dark Red Text.
- Click OK. All five cells containing INV-1002 or INV-1003 turn red.
This rule works in every version since Excel 2007 and updates live: correct INV-1003 in row 8 to INV-1006 and the colour vanishes from both INV-1003 cells.
Highlight only the second and later copies
The built-in rule colours every copy, including the original. Usually the first one is legitimate and only the repeats need attention. A formula rule with COUNTIF and a growing range does that. Check the logic in a helper column first:
| A | B | |
|---|---|---|
| 1 | Invoice | Count |
| 2 | INV-1001 | |
| 3 | INV-1002 | |
| 4 | INV-1003 | |
| 5 | INV-1002 | 2 |
| 6 | INV-1004 | |
| 7 | INV-1005 | |
| 8 | INV-1003 | |
| 9 | INV-1002 |
In row 5, INV-1002 has appeared twice so far (rows 3 and 5), so the count is 2: this is a repeat.
Result: 2
Now turn it into a rule:
- Select A2:A9 with A2 as the active cell.
- Home > Conditional Formatting > New Rule > Use a formula to determine which cells to format.
- Enter
=COUNTIF($A$2:$A2,$A2)>1and choose a fill colour. - Click OK. Rows 5, 8 and 9 are coloured; the first INV-1002 in row 3 and the first INV-1003 in row 4 are not.
Highlight the whole row
Select the whole table, for example A2:E9, and use the same kind of rule but lock the column with $: =COUNTIF($A$2:$A$9,$A2)>1. The $A makes every cell in the row look at the invoice number in column A. To treat a row as a duplicate only when two columns match, such as invoice and customer, use COUNTIFS: =COUNTIFS($A$2:$A$9,$A2,$B$2:$B$9,$B2)>1.
List the duplicate values
In Microsoft 365 you can also produce a list of the values that occur more than once. FILTER keeps the invoices whose count is above 1, and UNIQUE shows each of them once:
| A | B | C | |
|---|---|---|---|
| 1 | Invoice | ||
| 2 | INV-1001 | INV-1002 | |
| 3 | INV-1002 | INV-1003 | |
| 4 | INV-1003 | ||
| 5 | INV-1002 | ||
| 6 | INV-1004 | ||
| 7 | INV-1005 | ||
| 8 | INV-1003 | ||
| 9 | INV-1002 |
Two invoice numbers are duplicated.
In Excel 2016 and 2019, use the helper column approach instead: put =COUNTIF($A$2:$A$9,A2) next to each value, then filter that column for numbers greater than 1.
Pitfalls
- The Duplicate Values rule is not case-sensitive:
inv-1002andINV-1002count as duplicates. For a case-sensitive check use the rule=SUMPRODUCT(--EXACT($A$2:$A$9,$A2))>1. - COUNTIF treats text that looks like a number as a number, so
"0123"and123are seen as duplicates. Long numbers such as 16-digit card or account numbers are compared only to 15 significant digits, so different numbers can look like duplicates. Append&"*"to the criteria for text IDs:COUNTIF($A$2:$A$9,$A2&"*"). - Trailing spaces hide duplicates. Clean the column first with TRIM, see How to remove spaces in Excel.
- Many conditional formatting rules on large ranges slow the workbook down. Manage and delete old rules with Home > Conditional Formatting > Manage Rules.