Fix guide

Duplicate VLOOKUP keys in Google Sheets™? Find and fix wrong matches

Duplicate lookup keys are a quiet spreadsheet bug. VLOOKUP and XLOOKUP can return a real-looking answer, but it may be the first matching row instead of the row you meant. Here is how to find duplicate keys, decide whether they are valid, and avoid silently wrong results.

The quick test

If your lookup keys are in column A, add this helper formula beside the data:

=COUNTIF(A:A,A2)

Fill it down. Any result greater than 1 means that key appears more than once.

A | B Customer | Invoice CUST-001 | INV-100 CUST-002 | INV-101 CUST-001 | INV-144 =VLOOKUP("CUST-001", A:B, 2, FALSE) returns INV-100 The second CUST-001 row is hidden from the lookup.

Why duplicate keys are dangerous

A formula error like #N/A is obvious. A duplicate-key lookup is worse because the formula usually returns something. It just may not be the right thing.

That creates bad reports, wrong invoice matching, incorrect customer lookups, and dashboards that look clean while hiding duplicate source data.

Step 1 - List each duplicate key once

Use this when you want a clean list of the duplicated values:

=UNIQUE(FILTER(A2:A,A2:A<>"",COUNTIF(A2:A,A2:A)>1))

This returns each repeated key once. It is easier to review than scanning a helper column full of counts.

Tip: Use the same bounded range your sheet actually uses, for example A2:A500, if your data has many blank rows below it. This keeps the check fast and easier to read.

Step 2 - Count how many duplicate keys exist

This tells you whether the lookup column is clean:

=COUNTA(A2:A)-COUNTA(UNIQUE(FILTER(A2:A,A2:A<>"")))

A result of 0 means every populated key is unique. Any non-zero result means at least one key appears more than once.

Step 3 - Check whether duplicates are accidental or valid

Not every duplicate is wrong. The fix depends on what the key represents.

  • Customer ID, SKU, invoice ID, order ID: usually should be unique. Deduplicate the source data or fix the duplicate IDs.
  • Customer name, product category, status: duplicates are usually valid. Do not use them as a unique lookup key.
  • Email address: sometimes unique, sometimes not. Check whether one person can have multiple records.

Step 4 - If duplicates are valid, stop using VLOOKUP

If more than one row can match, VLOOKUP hides that fact. Use FILTER when you want all matching rows:

=FILTER(A:D,A:A=F2)

Use QUERY when you want a summarized view:

=QUERY(A:D,"select A, sum(D) where A is not null group by A",1)

The goal is to make the duplicate visible instead of pretending there is only one match.

Step 5 - If duplicates are accidental, clean the source

Do not hide accidental duplicates with IFERROR or extra lookup logic. Fix the source column first.

  1. Sort by the lookup key.
  2. Review every key with a helper count greater than 1.
  3. Merge true duplicates if they represent the same record.
  4. Assign a unique ID if multiple records are valid.
  5. Point formulas at the cleaned key column.

Step 6 - Watch for whitespace duplicates

CUST-001 and CUST-001 look almost identical, but they are different keys. Clean the lookup key before testing for duplicates:

=COUNTIF(ARRAYFORMULA(TRIM(A:A)),TRIM(A2))

If your imports come from CSVs, forms, or copied web tables, run this check before assuming the duplicate report is clean.

What SheetBrain checks

SheetBrain's free Check tab includes a duplicate_lookup_key detector. It looks for VLOOKUP and XLOOKUP formulas in the active sheet, checks the lookup-key column they depend on, and warns when that column contains duplicate values.

Scope matters: this detector checks current-sheet lookup ranges. It does not scan cross-sheet source ranges in this version, and it does not treat every duplicated column as an error unless a lookup formula actually depends on that column.

Find duplicate lookup keys before they break reports

Install SheetBrain and run the free Check tab. It scans the active sheet for duplicate lookup keys, mixed data types, visible formula errors, broken references, formula pattern outliers, and missing copied formulas. No AI quota, no API key, no credit card.

Install free on Google Workspace

TL;DR

  • Use =COUNTIF(A:A,A2) to see whether a lookup key appears more than once.
  • Use =UNIQUE(FILTER(A2:A,A2:A<>"",COUNTIF(A2:A,A2:A)>1)) to list repeated keys.
  • If duplicates are accidental, clean the source. Do not patch over the problem with more lookup logic.
  • If duplicates are valid, use FILTER or QUERY. VLOOKUP is the wrong tool when multiple rows can match.
  • Use SheetBrain Check when you want a quick scan for lookup formulas that depend on duplicate key columns.