Sub topic 6
Handling Missing Lookup Results
This chapter assumes you can enter and copy formulas, use absolute references such as $A$2:$B$100, and write a basic VLOOKUP. It covers what happens when a lookup finds nothing, and how to handle that case without hiding other problems.
Why lookups return #N/A
A lookup function returns #N/A ("not available") when it cannot find the value you asked for. This is the normal result for a missing key, so it is often not a mistake in the formula. A new product code that is not yet in the price list is one example. A customer ID with a stray space is another.
#N/A is different from errors that point to a broken formula, such as #REF! (a deleted column) or #NAME? (a misspelled function). You usually want to handle the first kind and still see the second kind.
Handling the missing case with IFNA
IFNA(value, value_if_na) returns the second argument only when the first argument evaluates to #N/A. All other errors pass through.
=IFNA(VLOOKUP(E2, $A$2:$B$100, 2, FALSE), "Not found")If E2 is missing from column A, the cell shows Not found. If the lookup range was damaged and returns #REF!, that error still appears. This is why IFNA is the safer wrapper for lookups.
Checking first with MATCH
You can also test whether a value exists before you use it. MATCH returns #N/A when it finds nothing, and ISNA turns that into TRUE or FALSE.
=IF(ISNA(MATCH(E2, $A$2:$A$100, 0)), "Missing", "Found")This is useful for a status column that flags missing keys, so you can filter on them. It does not return the looked-up value, so it works as a check beside the lookup and not as a replacement for it.
Chaining fallback lookups
Sometimes the value may live in one of two places, such as a current sheet and an archive sheet. Nest a second IFNA inside the first. The second lookup runs only when the first returns #N/A.
=IFNA(VLOOKUP(E2, Sheet1!$A$2:$B$100, 2, FALSE), IFNA(VLOOKUP(E2, Sheet2!$A$2:$B$100, 2, FALSE), "Not found"))Excel reads the formula from the inside out, but it evaluates the fallbacks in order, as the diagram shows.
Keep chains short. Beyond two or three levels the formula is hard to read and to debug. Consolidating the lists into one table is usually better.
Using XLOOKUP's if_not_found argument
XLOOKUP has a built-in fourth argument for the missing case, so you do not need a wrapper.
=XLOOKUP(E2, $A$2:$A$100, $B$2:$B$100, "Not found")Like IFNA, this argument responds only to a missing match. Other errors still appear. XLOOKUP is available in Excel 2021 and Microsoft 365. In older versions, use IFNA with VLOOKUP or INDEX/MATCH.
Choosing what to return
The fallback value affects any formula that uses the result.
| Fallback | Good for | Watch out for |
|---|---|---|
| `"Not found"` | Reports that people read | Text in a numeric column breaks arithmetic such as `+` and gives `#VALUE!` |
| `0` | Numeric columns that feed totals | A missing price looks like a real price of zero |
| `""` | Cells that should look blank | It is text, not an empty cell, so `ISBLANK` returns `FALSE` |
SUM ignores text, but =C2*D2 fails if either cell holds a message. If the result feeds more calculations, pick the fallback with those formulas in mind.
Common mistakes
- Wrapping a lookup in
IFERRORand never noticing that a#REF!or#NAME?is being replaced by "Not found". PreferIFNA. - Returning
0for missing prices, which understates totals without any warning. - Forgetting that trailing spaces or numbers stored as text cause false
#N/Aresults. Check the data when many lookups fail at once.
Exercise
A sheet looks up prices from $A$2:$B$100 using the code in E2. When the code is missing, the cell should show "Check code". Write the formula. Then explain why IFNA is better here than IFERROR.
Show answer
=IFNA(VLOOKUP(E2, $A$2:$B$100, 2, FALSE), "Check code"). IFNA replaces only #N/A, which is the "code not found" case. If the range is broken and the lookup returns #REF!, or the function name is misspelled and returns #NAME?, IFNA lets that error show so you can fix it. IFERROR would hide it behind "Check code".