Sub topic 6
Handling missing lookup results
This chapter covers what to do when a lookup cannot find its value. It assumes you can enter and copy formulas, use relative and absolute references, and write a basic IF and VLOOKUP. By the end you should be able to wrap a lookup so a missing key shows a clear message, without hiding other problems.
Why lookups fail in a predictable way
A lookup function searches a list for a key and returns something from the matching row. When the key is not in the list, Excel returns #N/A. The name stands for "not available," and here it means "no match was found."
Missing keys are a normal event in real data. A new product code may not be in the price list yet. A customer ID may have a typo. A trailing space may make "A100 " differ from "A100". Because this failure is expected, it is the one error you can handle on purpose.
Lookups can produce other errors too:
| Error | Typical cause in a lookup |
|---|---|
| `#N/A` | The lookup value is not in the lookup column. |
| `#REF!` | The column index is larger than the number of columns in the table, or a referenced range was deleted. |
| `#NAME?` | The function name is misspelled, or a named range does not exist. |
| `#VALUE!` | The lookup value is invalid for the function, for example a text value that is too long. |
Only the first is the "missing result" case. The others are mistakes in the formula or the workbook, and you usually want to see them.
The unprotected lookup
Suppose A2:B100 holds product codes and prices, and E2 holds a code to look up.
=VLOOKUP(E2, $A$2:$B$100, 2, FALSE)The FALSE at the end asks for an exact match. If E2 holds a code that is not in column A, the cell shows #N/A. That error spreads to every formula that uses the cell, so a single missing code can turn a whole total into #N/A.
Handling the missing case with IFNA
IFNA(value, value_if_na) returns value_if_na only when the first argument evaluates to #N/A. Any other result, including other errors, passes through unchanged.
=IFNA(VLOOKUP(E2, $A$2:$B$100, 2, FALSE), "Not found")This formula behaves as follows:
- A matching code returns its price.
- A missing code returns the text
Not found. - A bad column index returns
#REF!, so the formula mistake stays visible. - A misspelled function name returns
#NAME?, so that stays visible too.
That last point is the reason IFNA is the safer choice for lookups. It handles the one failure you expect and leaves the failures you do not.
Compare with IFERROR
IFERROR catches every error type. Wrapping the same lookup in IFERROR gives this:
=IFERROR(VLOOKUP(E2, $A$2:$B$100, 2, FALSE), "Not found")It works for a missing code. It also reports Not found if you type the column index as 5 in a two-column table, or if the table range points at a deleted area. The message is wrong in those cases. It says the key is missing when the formula itself is broken, and the cell gives no sign of the real cause.
Choosing what the fallback returns
The second argument is up to you. The choice affects how the result looks and how later formulas use it. Chapter content on replacement values goes deeper elsewhere in this tutorial, so this section covers only what matters for lookups.
- A message such as
"Not found"is clear to a reader. It is text, so a later calculation such as=F2*G2that uses it returns#VALUE!. 0keeps arithmetic working, but it looks like a real price of zero. Use it only when zero is a true and harmless default.- An empty string
""looks blank, but the cell is not empty. It contains text of zero length. Sums ignore it, but=F2*G2returns#VALUE!, andISBLANKreturnsFALSE.
A practical rule is to use a message when people read the sheet, and to use a value that your later formulas can handle when the result feeds a calculation.
Chained fallbacks across ranges or sheets
Sometimes a key can live in more than one place, such as a current price list and an archive. Nest IFNA calls so 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"))Read it from the inside out:
- Excel looks in
Sheet1. If it finds the code, it returns the price and stops. - If the first lookup returns
#N/A, Excel looks inSheet2. - If that lookup also returns
#N/A, the formula returnsNot found.
Because each layer uses IFNA, a #REF! in either lookup still appears. With IFERROR, a broken reference in Sheet1 would silently send every row to Sheet2, and you could end up with prices from the wrong list without noticing.
Keep chains short. Each added layer makes the formula harder to read. If you need three or more sources, consider combining the lists into one table, or put each lookup in its own helper column and combine them in a final column.
Built-in handling with XLOOKUP
In Excel versions that include XLOOKUP, you do not need a wrapper for the missing case. The fourth argument, if_not_found, returns your value only when no match exists.
=XLOOKUP(E2, $A$2:$A$100, $B$2:$B$100, "Not found")This behaves like IFNA around a lookup. Other errors, such as #REF! from a deleted range, still show. It is also shorter, and it avoids running the lookup twice in your head when you read it. XLOOKUP takes separate lookup and return ranges, so there is no column index to get wrong.
Two details are worth knowing:
if_not_foundhandles only the missing-match case. If the return range contains an error value in the matching row, XLOOKUP returns that error.- If you leave
if_not_foundout, a missing key returns#N/A, as VLOOKUP does.
Testing for a missing key without wrapping the lookup
Sometimes you want to know whether a key exists, not retrieve a value. Use MATCH with exact matching and test for #N/A with ISNA.
=IF(ISNA(MATCH(E2, $A$2:$A$100, 0)), "Missing", "Found")MATCH(E2, $A$2:$A$100, 0) returns the position of the key, or #N/A if it is absent. ISNA returns TRUE only for #N/A, so the test is as narrow as IFNA. This pattern is useful for a validation column that flags rows before a report is built.
A similar idea applies to division. Rather than catching an error after the fact, check the cause first:
=IF(B2=0, "", A2/B2)This handles only the zero-divisor case. A #VALUE! from text in A2 still appears, which is what you want.
When to prefer each approach
| Situation | Better choice | Reason |
|---|---|---|
| VLOOKUP or INDEX/MATCH where a missing key is expected | `IFNA` | Catches only `#N/A`. |
| Modern Excel with XLOOKUP | `if_not_found` argument | No wrapper needed. |
| Key may be in one of several lists | Nested `IFNA` | Moves to the next list only on a miss. |
| You need to flag missing keys, not fetch values | `IF(ISNA(MATCH(...)))` | Returns a clear status. |
| Several unrelated errors are all acceptable | `IFERROR` | Use only after you know the possible causes. |
Common mistakes
- Using IFERROR by habit on a lookup. A typo in the range becomes a column of "Not found" values. Switch to IFNA.
- Wrapping the whole formula instead of the lookup. In
=IFNA(VLOOKUP(...)*1.2, 0), a missing key is turned into0, and then the tax or markup is skipped. Decide whether that is what you want. - Forgetting exact match.
VLOOKUP(E2, range, 2)with the fourth argument omitted uses approximate matching and can return a wrong row instead of#N/A. No error handler can fix a wrong answer that is not an error. Always passFALSEor0for exact lookups. - Hidden spaces and text-versus-number mismatches. A code stored as text will not match the same code stored as a number. If many keys come back missing, check the data before changing the formula. The
TRIMfunction and theVALUEfunction help with cleanup. - Treating a fallback of
""as an empty cell. It is text. Test with=F2="", notISBLANK(F2).
Worked example
You have an order list in D2:E50, with product codes in column D. The price list is A2:B100. You want a price column, and you want to count the codes that have no price.
Put this in F2 and copy it down:
=IFNA(VLOOKUP(D2, $A$2:$B$100, 2, FALSE), "Not found")Because the fallback is text, a later extended-price formula needs a guard. In G2:
=IF(ISNUMBER(F2), E2*F2, "")To count unpriced rows, use:
=COUNTIF(F2:F50, "Not found")The pieces fit together. The lookup handles the expected miss, the guard stops text from reaching arithmetic, and the count turns misses into a number you can act on. If someone deletes part of the price list and a #REF! appears in column F, it shows up, and ISNUMBER returns FALSE for it, so you will see the problem in the F column itself.
Exercise
A price table sits in A2:C100 with codes in column A, prices in column B and categories in column C. A colleague writes =IFERROR(VLOOKUP(E2, $A$2:$B$100, 3, FALSE), "Not found"). Every row shows "Not found", even for codes that exist. What is wrong, and how do you rewrite the formula so this kind of mistake is visible?
Show answer
The table range $A$2:$B$100 has only two columns, so a column index of 3 returns #REF! for every row. IFERROR catches #REF! and shows "Not found", which hides the mistake. Fix the index to 2 (for price) or widen the range to $A$2:$C$100 (for category). Use IFNA so only a true missing code is replaced: =IFNA(VLOOKUP(E2, $A$2:$B$100, 2, FALSE), "Not found"). A wrong index then shows #REF!.
Exercise
Write a formula that returns the price from Sheet1!A2:B100 for the code in E2. If the code is not there, it should try Sheet2!A2:B100. If it is in neither, it should return "Not found". Then give a formula that uses XLOOKUP for a single sheet.
Show answer
Chained: =IFNA(VLOOKUP(E2, Sheet1!$A$2:$B$100, 2, FALSE), IFNA(VLOOKUP(E2, Sheet2!$A$2:$B$100, 2, FALSE), "Not found")). XLOOKUP for one sheet: =XLOOKUP(E2, $A$2:$A$100, $B$2:$B$100, "Not found").