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.

Beginner COUNTIF COUNTIFS UNIQUE FILTER

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)

  1. Select A2:A9 (only the data, not the header).
  2. Go to Home > Conditional Formatting > Highlight Cells Rules > Duplicate Values.
  3. 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.
  4. 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:

B5fx=COUNTIF($A$2:A5,A5)
AB
1InvoiceCount
2INV-1001
3INV-1002
4INV-1003
5INV-10022
6INV-1004
7INV-1005
8INV-1003
9INV-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:

  1. Select A2:A9 with A2 as the active cell.
  2. Home > Conditional Formatting > New Rule > Use a formula to determine which cells to format.
  3. Enter =COUNTIF($A$2:$A2,$A2)>1 and choose a fill colour.
  4. 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.
Watch out. Write the formula for the active cell (the top-left cell of your selection, here A2). Excel adjusts it for every other cell. If A5 was active when you created the rule, the references would be shifted by three rows and the wrong cells would light up. Conditional formatting, including formula-based rules explains this in detail.

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:

C2fx=UNIQUE(FILTER(A2:A9,COUNTIF(A2:A9,A2:A9)>1))
ABC
1Invoice
2INV-1001INV-1002
3INV-1002INV-1003
4INV-1003
5INV-1002
6INV-1004
7INV-1005
8INV-1003
9INV-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-1002 and INV-1002 count 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" and 123 are 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.
Tip. Once you have reviewed the coloured cells, you can filter by colour (the filter arrow > Filter by Color) to show only the duplicates and delete them. Or skip straight to How to remove duplicates in Excel. To compare two different lists, see How to find duplicates between two lists in Excel.
⬇Practice workbookExamples with live formulas + practice sheets · .xlsx · 14 KB

More how-to recipes