New Tool Radar

AI for Data & Spreadsheets

How to Find Trailing Spaces That Break a Lookup in Excel

Find trailing spaces that break a lookup even though the values look identical.

Schematic with three steps: Compare the lengths of the two values; Find which side carries the extra characters; Clean both sides with TRIM and re-test.

A lookup fails with #N/A even though the value is visibly in the table, and the cause is often a space after the last character that the eye cannot see. “East ” with a trailing space is not the same value as “East” to Excel, so the lookup finds nothing. When a lookup fails on a value that looks right, check the length of the value before doubting the formula.

What you need

  • The lookup formula that returns #N/A
  • The lookup value and the matching value in the table
  • A helper column for a LEN check

Step 1: Compare the lengths of the two values

In a helper cell, enter =LEN on the lookup value and =LEN on the table value it should match. If the lengths differ, hidden characters are present; the difference in length is the number of hidden characters.

Step 2: Find which side carries the extra characters

Check the length of each side against the visible text. The side whose length is longer than the visible characters holds the trailing spaces; mark it for cleaning.

Step 3: Clean both sides with TRIM and re-test

Apply =TRIM to both the lookup column and the table column in helper columns, paste the results as values, and run the lookup again. It should now find the match; if it still fails, check for non-breaking spaces with CHAR(160).

Worked example: synthetic region lookup

The table below is a synthetic example. It shows the expected result of checking trailing spaces; no formula was run.

Check Value Result
Lookup value shown East Looks correct
Length of the lookup value 4 East is 4 letters
Length of the table value 5 One extra character
Hidden character found Trailing space In the table value
Lookup after TRIM on both sides Found Returns the right row

Expected result (UNTESTED). the lookup fails because the table value is 5 characters long, one more than the visible East; the extra character is a trailing space. TRIM on both sides makes the lookup find the right row. This check was not run live; the table shows the expected result for the synthetic example.

Limits

  • TRIM removes only the ordinary space (character 32); a non-breaking space (character 160) needs SUBSTITUTE first.
  • TRIM also collapses double spaces inside the text to one, which can change codes where double spaces matter.
  • A lookup value typed with a trailing space fails the same way; check the value you type, not only the table.
  • LEN counts characters, so a value that looks short but counts long may hold a line break instead of a space.

Sources

See all