Flag Duplicate Values

Excel Formulas › Logical

All versionsCOUNTIFCond. formatting

To mark which entries in a list repeat, count how many times each value appears with COUNTIF and flag the ones with a count above 1. The same COUNTIF test drives a conditional-formatting rule to highlight them in color.


Quick formula: in B2, copied down, to label repeats in column A:
=IF(COUNTIF($A$2:$A$8, A2)>1, "Duplicate", "")
COUNTIF counts how many times A2 appears in the whole locked list; more than one means it’s a duplicate.

Functions used (tap for the full reference guide):

The example

A list of order IDs — two of them repeat.

AB
1Order IDFlag
2A-100
3A-101Duplicate
4A-102
5A-101Duplicate
6A-103

The formula

The flag formula, filled down:

=IF(COUNTIF($A$2:$A$6, A2)>1, "Duplicate", "") // A-101 appears twice → flagged

How it works

One COUNTIF does the work:

  1. COUNTIF($A$2:$A$6, A2) counts how many cells in the locked list equal the current value.
  2. The list range is absolute ($A$2:$A$6) so it stays fixed as you copy; the tested value A2 is relative so it moves row by row.
  3. If the count is greater than 1, the value occurs more than once → "Duplicate"; otherwise a blank string.
  4. To flag only the second and later occurrences, use a growing range: COUNTIF($A$2:A2, A2)>1.

Try it: interactive demo

Live demo

Type a comma-separated list; duplicates are flagged the way the formula would.

Variations

Highlight duplicates with conditional formatting

Select the list, then Home → Conditional Formatting → New Rule → Use a formula, and enter:

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

Pick a fill color. Every duplicate cell turns that color, updating live as data changes.

Flag only repeats (keep the first)

Counts occurrences up to the current row, so the first stays unflagged:

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

Duplicates across two columns

Concatenate the key first:

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

Pitfalls & errors

Everything (or nothing) flagged. The list range must be locked with $. Without it, the range drifts as you copy and the counts go wrong.

COUNTIF ignores case. "ABC" and "abc" count as the same. For case-sensitive duplicate detection use SUMPRODUCT(--EXACT($A$2:$A$8, A2))>1.

Numbers stored as text. "100" (text) and 100 (number) may or may not be treated as equal depending on the cell — clean the column first if results look off.

Practice workbook

📊
Download the free Flag Duplicate Values practice workbook
The ID list with a live duplicate flag, the first-vs-repeat variant, and the two-column key, plus 4 challenges with answers. No sign-up required.

Frequently asked questions

How do I flag duplicates in Excel with a formula?
Use =IF(COUNTIF($A$2:$A$8, A2)>1, "Duplicate", "") and fill it down. COUNTIF counts how many times each value appears in the locked list; a count above 1 means it repeats.
How do I highlight duplicates instead of labeling them?
Select the range, Home > Conditional Formatting > New Rule > Use a formula, enter =COUNTIF($A$2:$A$8, A2)>1, and choose a fill color.
How do I flag duplicates but keep the first occurrence?
Use a growing range so each value is counted only up to its own row: =IF(COUNTIF($A$2:A2, A2)>1, "Repeat", "").

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: Count unique values · COUNTIFS with multiple criteria · Convert scores to grades

Function references: COUNTIF · IF