Highlight Duplicate Values

Excel Formulas › Conditional Formatting

All versionsCOUNTIF

Spot repeats at a glance. A conditional-formatting rule built on COUNTIF shades every value that appears more than once — and a tiny tweak lets you highlight only the second-and-later copies instead.


Quick formula: select your range (say A2:A20), then add a formula CF rule:
=COUNTIF($A$2:$A$20, A2) > 1
Every cell whose value occurs more than once in the range gets the format. The range is locked with $; the test cell A2 is relative so it walks down the column.

Functions used (tap for the full reference guide):

The example

Order IDs — the repeated ones are flagged.

AB
1Order IDCount
2A-1002
3A-1011
4A-1002
5A-1021

The formula

The conditional-formatting rule formula:

=COUNTIF($A$2:$A$20, A2) > 1 // TRUE for any value seen 2+ times

How it works

Conditional formatting applies a format wherever the rule returns TRUE:

  1. Select the range, then Home → Conditional Formatting → New Rule → Use a formula.
  2. Enter =COUNTIF($A$2:$A$20, A2) > 1 — absolute range, relative test cell (matching the active cell of your selection).
  3. COUNTIF counts how many times the current value appears; > 1 means it’s a duplicate.
  4. Pick a fill color and click OK. Excel evaluates the rule for every cell, shading all duplicates.

Keep the first, flag the rest? Use =COUNTIF($A$2:A2, A2) > 1 — the range grows from the top to the current row, so only the 2nd+ occurrences are TRUE. There’s also a built-in shortcut: Conditional Formatting → Highlight Cells Rules → Duplicate Values.

Try it: interactive demo

Live demo

Edit the list; duplicates highlight automatically.

Variations

Flag only repeats (keep first)

Expanding range from the top:

=COUNTIF($A$2:A2, A2) > 1

Unique values only

Highlight the one-offs instead:

=COUNTIF($A$2:$A$20, A2) = 1

Duplicates across two columns

Match the whole row key:

=COUNTIFS($A$2:$A$20,A2,$B$2:$B$20,B2) > 1

Pitfalls & errors

Lock the range, not the cell. Use $A$2:$A$20 (absolute) but a relative test cell A2. Locking the test cell too makes every row test the same value.

Match the active cell. The relative reference must match the top-left (active) cell of your selection, or the rule shifts and highlights the wrong cells.

COUNTIF ignores case and treats numbers loosely. “abc” and “ABC” count as duplicates; for case-sensitive matching use a SUMPRODUCT/EXACT rule.

Practice workbook

📊
Download the free Highlight Duplicate Values practice workbook
A live duplicate-highlight sheet with the keep-first, unique-only, and two-column rules already applied, plus 4 challenges with answers. No sign-up required.

Frequently asked questions

How do I highlight duplicate values in Excel with conditional formatting?
Select the range, add a formula rule =COUNTIF($A$2:$A$20, A2) > 1, and choose a fill. Every value that appears more than once gets highlighted.
How do I highlight only the duplicates after the first one?
Use an expanding range: =COUNTIF($A$2:A2, A2) > 1. It only returns TRUE for the second and later occurrences.
Is there a built-in shortcut?
Yes — Conditional Formatting → Highlight Cells Rules → Duplicate Values flags duplicates without a formula, though the formula version is more flexible.

Stop fighting formulas. Learn them in a day.

This recipe is one of hundreds of real-world formulas we teach. Our Excel Formulas & Functions class covers lookups, logic, text, and dynamic arrays hands-on — live in Dallas–Fort Worth, Houston, Austin, Oklahoma City, Denver, or online.

See the Formulas & Functions Class

Related formulas: Flag duplicates · Conditional formatting with a formula · Count unique values

Function references: COUNTIF