A lookup for the code 101 fails even though 101 is visibly in the table, because one side stores the code as the number 101 and the other as the text “101”. To Excel they are different values, so no match is found. The fix is to make both keys the same type, but first you have to prove which side is which.
What you need
- The lookup formula that returns #N/A
- The lookup key and the key column in the table
- A helper column for a type check
Step 1: Check the type of each side with ISTEXT and ISNUMBER
In helper cells, enter =ISTEXT on the lookup key and on a key from the table, and =ISNUMBER on both. One side will return TRUE for text and the other TRUE for number; that mismatch is the fault.
Step 2: Check the alignment as a second clue
Look at how the keys align in their cells: numbers align right and text aligns left by default. A key aligned left in a column of right-aligned numbers is text, and the reverse is also a clue.
Step 3: Convert one side to match the other and re-test
Convert the text keys to numbers with VALUE, or the number keys to text with TEXT, so both sides are the same type, then run the lookup again. It should now find the match; if it still fails, check for trailing spaces.
Worked example: synthetic product code lookup
The table below is a synthetic example. It shows the expected result of diagnosing a text-versus-number mismatch; no formula was run.
| Check | Value | Result |
|---|---|---|
| Lookup key | 101 | Typed as text |
| Table key | 101 | Stored as a number |
| ISTEXT on the lookup key | TRUE | Text |
| ISNUMBER on the table key | TRUE | Number |
| Lookup after converting both to numbers | Found | Returns the right row |
Expected result (UNTESTED). the lookup fails because the lookup key is the text “101” while the table key is the number 101. Converting the lookup key to a number makes the lookup find the right row. This check was not run live; the table shows the expected result for the synthetic example.
Limits
- VALUE converts text that looks like a number, but fails on text with spaces or letters; trim it first.
- Converting a number key to text with TEXT needs a format, such as “0”, or leading zeros can be lost.
- A green triangle in the corner of a cell marks a number stored as text; use it as a quick visual check.
- Both sides must be the same type; converting only one side leaves the mismatch in place.
