Sub topic 8
Fixing #N/A: lookups that find nothing
This chapter assumes you can enter formulas, use cell references and ranges, and have used VLOOKUP at a basic level. It covers why lookups return #N/A and how to fix the cause or handle the result with IFNA.
What #N/A means
#N/A stands for "not available." Lookup functions such as VLOOKUP, HLOOKUP, MATCH and XLOOKUP return it when they find no match for the value you gave them. Often this is correct behavior. A product code that isn't in the price list should produce no price.
#N/A is different from most other errors. #REF! and #NAME? point to a broken formula. #N/A usually means the formula works but the data didn't match. Check the data first.
Common causes
A lookup fails to match for a small number of reasons:
- The value really isn't in the lookup range.
- The value has extra spaces, such as
"A100 "instead of"A100". - One side is a number and the other is text. For example,
1001and"1001"look the same but do not match. - You asked for an exact match, but the spelling differs slightly.
- The lookup range doesn't include the column that holds the lookup values. VLOOKUP searches only the first column of the range.
=VLOOKUP(E2,A2:B100,2,FALSE)The last argument, FALSE, requests an exact match. If E2 holds 1001 as text and column A holds the number 1001, this formula returns #N/A even though both cells look identical.
Diagnosing a lookup failure
Work through these checks in order.
- Click the lookup cell and the matching cell in the range. Look at the alignment. By default, numbers align right and text aligns left. A mismatch suggests a type problem.
- Test the value with
=LEN(E2). If the result is longer than the visible characters, there are hidden spaces. - Use
=ISNUMBER(E2)and=ISNUMBER(A2)to compare types. - Search the lookup column with Ctrl+F to confirm that the value exists.
The diagram shows the decision path.
Fixing the data
If the problem is spaces or types, fix the data or clean the lookup value inside the formula.
=VLOOKUP(TRIM(E2),A2:B100,2,FALSE)TRIM removes leading and trailing spaces from E2 before the search. If the lookup value is text but the table holds numbers, wrap it with VALUE:
=VLOOKUP(VALUE(TRIM(E2)),A2:B100,2,FALSE)Fixing the source data is better when you control it, because every future formula then benefits.
Handling expected #N/A with IFNA
Some missing matches are legitimate. In that case, show a readable message instead of the error.
=IFNA(VLOOKUP(E2,A2:B100,2,FALSE),"Not found")IFNA replaces only #N/A. If the same formula later returns #REF! because someone deleted a column, that error still appears, so you notice the real fault.
Quick reference
| Symptom | Likely cause | Fix |
|---|---|---|
| Value visible in the table but still #N/A | Number stored as text, or the reverse | Convert with VALUE, or fix the source cells |
| #N/A only for some rows | Trailing spaces | Use TRIM |
| #N/A for every row | Wrong lookup range or column order | Make sure the lookup value is in the first column of the range |
| #N/A for truly absent items | Expected missing data | Use IFNA with a message |
Exercise
A formula =VLOOKUP(E2,A2:B100,2,FALSE) returns #N/A. Column A contains the code 5001 and E2 shows 5001, but LEN(E2) returns 5. What is the likely cause, and what formula fixes it?
Show answer
E2 contains a hidden character, most likely a trailing space, because LEN counts 5 characters for a four-digit code. Use =VLOOKUP(VALUE(TRIM(E2)),A2:B100,2,FALSE) if the codes in column A are numbers, or =VLOOKUP(TRIM(E2),A2:B100,2,FALSE) if they are text. Wrap it in IFNA if you want a "Not found" message for codes that are truly missing.