Invisible spaces and the #N/A they cause
Disclosure: This is the English edition of an explainer I originally made in Japanese. It was translated with AI assistance, then reviewed and edited. Every example below uses dummy data. Two product codes look exactly the same, but VLOOKUP returns #N/A. This post shows you how an invisible space breaks the lookup, how to spot it with LEN, and how to remove it with Find & Replace. The received…
Invisible spaces can cause problems when using Excel's VLOOKUP function, as they make otherwise identical-looking values appear different to the spreadsheet program. In one example, two product codes seemed identical when viewed, both reading "A-102". However, when the VLOOKUP function searched for this code in the master list, it returned #N/A, as if the code did not exist. This happened because one code had an extra trailing space at the end, making it six characters long instead of the expected five.
To identify this hidden space, the LEN function can be used to count the number of characters in each cell. If the lengths do not match despite the cells appearing the same, a trailing space is likely the culprit. Once the extra space is discovered, Excel's Find & Replace feature can be employed to eliminate the space by replacing all instances of a single space with nothing. After removing the space, the VLOOKUP should work correctly and return the expected stock count.
One potential pitfall to watch for is the full-width space, which can appear identically to a regular space but is wider in size. This can also disrupt lookups in the same way. If the regular Find & Replace does not resolve the issue, it may be necessary to repeat the process using the full-width space as the search term. Repeated LEN checks can help ensure all invisible spaces are accounted for to avoid lookup mismatches.
Rewritten by urgent.news; may contain errors — check the original.
Source: dev.to