Answers / Question 14

Why VLOOKUP or XLOOKUP returns #N/A even when the value is right there (Excel + Google Sheets)

The usual invisible causes of a failed lookup: trailing spaces, numbers stored as text, approximate match without FALSE, and looking left with VLOOKUP, plus copy-paste fixes for Excel and Sheets.

The problem

The lookup value is sitting in the table; you can see it with your own eyes. Yet VLOOKUP or XLOOKUP comes back with #N/A. The match is almost always failing for a reason you can't see in the cell: a trailing space, a number stored as text, approximate matching, or (with VLOOKUP) looking for a column to the left of the key.

Inspired by a public question on Stack Overflow. The problem above is described in our own words and the solution below is ours.

Prove the cells really match

Pick one row you expect to match. If the lookup value is in A2 and the table key you think matches is in Sheet2!A100:

TRUE only when the two cells are identicalFormula
=A2=Sheet2!A100

If that returns FALSE, the values differ somehow. The checks below find the usual culprits.

Cause 1: trailing or leading spaces

A value that looks like ABC-12 but is stored as ABC-12 (with a space) won't match. Wrap both sides in TRIM, or clean the table once.

Excel / Sheets: exact VLOOKUP, trim the lookup valueFormula
=VLOOKUP(TRIM(A2), Sheet2!$A$2:$D$500, 2, FALSE)
XLOOKUP, trim both sides (Excel 365 / Sheets)Formula
=XLOOKUP(TRIM(A2), TRIM(Sheet2!$A$2:$A$500), Sheet2!$B$2:$B$500, "No match")

In Sheets you can also run Data → Data cleanup → Trim whitespace on the key column so the stored values stay clean.

Cause 2: number stored as text

101 (a number) is not the same as "101" (text). Check one cell:

TRUE means a real number; FALSE means textFormula
=ISNUMBER(Sheet2!A100)

Force both sides to the same type. Prefer numbers when the key is numeric:

Treat the lookup value as a numberFormula
=VLOOKUP(VALUE(TRIM(A2)), Sheet2!$A$2:$D$500, 2, FALSE)
Or compare everything as textFormula
=VLOOKUP(TEXT(A2, "0"), Sheet2!$A$2:$D$500, 2, FALSE)

In Excel, a green triangle on a cell often means “number stored as text”. Select the column → warning icon → Convert to Number, or use Data → Text to Columns and finish with General.

Cause 3: approximate match (missing FALSE)

VLOOKUP's fourth argument defaults to approximate match. On an unsorted table that can return #N/A or, worse, the wrong row. Always pass FALSE (or 0) for an exact match:

Exact-match VLOOKUPFormula
=VLOOKUP(A2, Sheet2!$A$2:$D$500, 2, FALSE)

XLOOKUP defaults to exact match, which is one reason it's safer. In Sheets, VLOOKUP(..., FALSE) behaves the same way.

Cause 4: VLOOKUP can't look left

VLOOKUP only returns a column to the right of the key. If the value you need sits to the left of the ID column, it will never find it that way. Use XLOOKUP (or INDEX/MATCH) instead:

Excel 365 / Sheets: look up left or rightFormula
=XLOOKUP(A2, Sheet2!$C$2:$C$500, Sheet2!$A$2:$A$500, "No match")
Older Excel: INDEX/MATCH looking leftFormula
=IFERROR(INDEX(Sheet2!$A$2:$A$500, MATCH(A2, Sheet2!$C$2:$C$500, 0)), "No match")

Good to know

Formulas follow documented Google Sheets / Excel behavior; they aren't machine-tested, so try them on a copy first. Always try new automations on a copy of your sheet first.