Audit Duplicate Keys

Excel Formulas › Auditing & Error-Proofing

All versionsCOUNTIF

IDs, invoice numbers, and SKUs are supposed to be unique. A COUNTIF over the key column flags any value that appears more than once — duplicates that would break lookups and double-count totals.


Quick formula: flag keys that appear more than once:
=IF(COUNTIF(key_column, A2) > 1, "Duplicate", "Unique")
Count each key across the whole column; more than one means it's duplicated and needs investigation.

Functions used (tap for the full reference guide):

The example

Invoice INV-100 appears twice.

AB
1KeyCheck
2INV-100Duplicate
3INV-101Unique

The formula

The formula:

=IF(COUNTIF(key_column, A2) > 1, "Duplicate", "Unique") // appears more than once

How it works

How it works:

  1. COUNTIF(key_column, A2) counts every occurrence of the key in the whole column.
  2. Greater than 1 means the key is duplicated — both (or all) copies get flagged.
  3. Duplicate keys silently break VLOOKUP/XLOOKUP (only the first match returns) and double-count sums.
  4. Count the total duplicate keys with a SUMPRODUCT over the flags.

Duplicate keys are silent lookup poison. VLOOKUP returns only the first match for a duplicated key, so a second invoice with the same number quietly returns the wrong amount — no error, just bad data. Auditing keys for uniqueness before relying on them in lookups or joins prevents the most insidious class of spreadsheet bug.

Try it: interactive demo

Live demo

Keys, one per line.

Variations

Count duplicate keys

How many repeat:

=SUMPRODUCT((COUNTIF(keys,keys)>1)*1) - distinct_dups

First vs later

Keep first:

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

Duplicate within group

Key + category:

=COUNTIFS(key,A2,grp,B2)>1

Pitfalls & errors

Breaks lookups. VLOOKUP returns only the first match for a duplicated key.

Whole column. Use a fixed range so every copy is counted, including the first.

Normalize keys. “INV-100” and “inv-100 ” may be the same — clean before counting.

Practice workbook

📊
Download the free Audit Duplicate Keys practice workbook
A duplicate-key sheet with the count, first-vs-later, and within-group variants, plus 4 challenges with answers. No sign-up required.

Frequently asked questions

How do I audit duplicate keys in Excel?
Flag repeats with =IF(COUNTIF(key_column, A2)>1, "Duplicate", "Unique") across the whole key column.
Why are duplicate keys dangerous?
VLOOKUP/XLOOKUP return only the first match, so a duplicated ID silently returns the wrong value and double-counts sums.
How do I keep only the first occurrence?
Use a running count: =IF(COUNTIF($A$2:A2,A2)>1,"Repeat","First") and filter to First.

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 · Flag first duplicate · Reconcile two lists

Function references: COUNTIF