Sub topic 4
Catching only #N/A with IFNA
Prerequisites and scope
This chapter assumes you can enter and copy formulas, you understand relative and absolute references ($A$2:$B$100), and you have used IF and VLOOKUP before. It covers one function, IFNA, and the situations where it is the right tool. The previous chapter covered IFERROR, which catches every error type. Here you will see why a narrower handler is often safer.
What IFNA does
IFNA checks one expression. If that expression returns the #N/A error, IFNA returns a replacement value you supply. For any other result, including every other error type, it returns the original result unchanged.
The syntax has two arguments:
=IFNA(value, value_if_na)valueis the formula or reference to test.value_if_nais what to return whenvalueis#N/A.
#N/A means "not available". Excel's lookup functions (VLOOKUP, HLOOKUP, LOOKUP, MATCH, and XLOOKUP when no fallback is given) return it when they cannot find the value you asked for. That makes #N/A a normal outcome for a lookup against incomplete data. It does not usually mean your formula is broken.
IFNA is available in Excel 2013 and later, and in Excel for the web and Microsoft 365. In Excel 2010 and earlier you must use IF(ISNA(...), ...) instead, which is covered later in this chapter.
A first example
Suppose column A holds product codes and column B holds prices. Cell E2 contains a code to look up. This formula returns the price, or a message when the code is not in the list:
=IFNA(VLOOKUP(E2, $A$2:$B$100, 2, FALSE), "Not found")The pieces work like this:
VLOOKUPsearches column A for the value in E2. TheFALSEargument asks for an exact match.- If it finds the code, it returns the matching price from column B.
IFNApasses that price through. - If it does not find the code,
VLOOKUPreturns#N/A.IFNAreplaces it with the text "Not found".
The absolute references ($A$2:$B$100) keep the lookup range fixed when you copy the formula down a column. The reference E2 is relative, so each row looks up its own code.
What IFNA leaves alone
The key property of IFNA is what it does not catch. Consider the same formula after someone deletes column B from the sheet. The lookup range collapses and VLOOKUP returns #REF!. Because #REF! is not #N/A, IFNA lets it through, and the cell shows #REF!.
That is the behavior you want. The missing code is an expected data condition, so you handle it. The deleted column is a structural fault, so you want to see it.
The table below shows how the two functions treat each error type when they wrap a formula that produces it.
| Error produced | Typical cause | IFNA | IFERROR |
|---|---|---|---|
| `#N/A` | Lookup value not found | Replaced | Replaced |
| `#DIV/0!` | Division by zero or an empty cell | Passed through | Replaced |
| `#VALUE!` | Wrong data type, such as text in arithmetic | Passed through | Replaced |
| `#REF!` | Reference to a deleted cell, row or column | Passed through | Replaced |
| `#NAME?` | Misspelled function or undefined name | Passed through | Replaced |
| `#NUM!` | Invalid number, such as the square root of a negative | Passed through | Replaced |
| `#NULL!` | Incorrect range operator, such as a missing colon or comma | Passed through | Replaced |
Only the first row behaves the same in both functions.
How the evaluation flows
The diagram shows the decision IFNA makes for each cell.
Two details follow from this flow.
IFNAevaluates the first argument once. You do not need to repeat the lookup to test it, which is an advantage over the olderIF(ISNA(VLOOKUP(...)), "Not found", VLOOKUP(...))pattern. That pattern runs the lookup twice and is longer to read and maintain.- The
value_if_naargument is only used when needed. You can put a longer expression there, such as another lookup, and it is not a cost for rows that succeed.
Why IFNA suits lookups
Lookups fail for two different reasons.
- The data does not contain the key. This is a business fact. A new product has no price yet, or a customer is not in the master list.
- The formula or its inputs are wrong. The range points at the wrong place, a column was deleted, or a function name is misspelled.
IFNA separates these. Case 1 produces #N/A, which you handle. Case 2 usually produces #REF!, #NAME? or #VALUE!, which stay visible so you notice them.
Using IFERROR on the same lookup would hide both. A broken lookup range would then display "Not found" in every row, and the report would look plausible while being wrong. This is the reason the spine recommends IFNA for lookups.
Be aware of one limit. VLOOKUP returns #N/A for a bad col_index_num only when it is larger than the table width in some cases, and #REF! in others. Do not rely on the error type alone to prove a formula is correct. Test your lookup on at least one known-good and one known-missing key.
Choosing the replacement value
The second argument can be a number, text, an empty string or another formula. The choice affects every formula that depends on the cell.
=IFNA(VLOOKUP(E2, $A$2:$B$100, 2, FALSE), 0)Returning 0 keeps the cell numeric, so sums and products still work. The risk is that a missing price becomes a price of zero. An average will include that zero and come out lower than the true figure.
=IFNA(VLOOKUP(E2, $A$2:$B$100, 2, FALSE), "")Returning "" looks blank, but it is text. SUM and AVERAGE ignore text in ranges, so totals are not distorted. A direct operation such as =F2*2 on that cell returns #VALUE!, because the cell holds text. COUNTA also counts it as a non-empty cell, and ISBLANK returns FALSE.
=IFNA(VLOOKUP(E2, $A$2:$B$100, 2, FALSE), "Not found")A message is the clearest for a reader and can be filtered on. It has the same downstream behavior as "": ranges ignore it, direct arithmetic fails.
| Replacement | Looks like | `SUM` over range | `=F2*2` on the cell | Best when |
|---|---|---|---|---|
| `0` | A zero | Adds 0 | Returns 0 | Missing truly means none |
| `""` | Blank | Ignored | `#VALUE!` | The report should look clean |
| `"Not found"` | Text | Ignored | `#VALUE!` | People need to see the gap |
Chained fallback lookups
Sometimes the value may live in one of several places. You can nest IFNA so that each failure moves to the next source.
=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:
- The outer
IFNAtriesSheet1. If a price is found, the formula returns it and stops. - If
Sheet1returns#N/A, the second argument is evaluated. That is anotherIFNAthat triesSheet2. - If
Sheet2also returns#N/A, the text "Not found" is returned.
Because IFNA passes other errors through, a broken reference to Sheet1 shows #REF! and does not silently fall through to Sheet2. If the first sheet's lookup were wrapped in IFERROR, a fault in that first range would be hidden and the second sheet would supply a value, possibly the wrong one.
Keep chains short. Three or more levels become hard to read. If you need many sources, consolidate the data into one table or use a helper column.
Alternatives to wrapping a lookup
XLOOKUP's built-in argument
In Excel 2021 and Microsoft 365, XLOOKUP has a fourth argument that is returned when no match is found:
=XLOOKUP(E2, $A$2:$A$100, $B$2:$B$100, "Not found")This handles only the missing-value case, the same scope as IFNA, with no wrapper. It also avoids the col_index_num problem, because you give separate lookup and return ranges. A caveat is that the argument covers missing matches only. If the lookup or return range itself contains an error value in the matched row, that error is still returned.
Testing first with ISNA
You can test for #N/A explicitly and branch on the result:
=IF(ISNA(MATCH(E2, $A$2:$A$100, 0)), "Missing", "Found")ISNA returns TRUE only for #N/A, so it has the same selectivity as IFNA. This form suits cases where you want to label presence, not return a looked-up value. It is also the pattern to use in Excel 2010 and earlier.
Common mistakes
- Using IFERROR on a lookup out of habit. It hides structural faults. Prefer
IFNA. - Treating
""as an empty cell. It is text.ISBLANKreturnsFALSEandCOUNTAcounts it. - Replacing with 0 when the value is truly unknown. Averages and minimums become wrong without any visible sign.
- Wrapping a formula that cannot return
#N/A.IFNA(A2/B2, 0)does nothing for a zero divisor, because that gives#DIV/0!. UseIF(B2=0, ...)orIFERRORfor that case. - Expecting a text mismatch to be reported. A code stored as text in one list and as a number in the other returns
#N/A.IFNAwill label it "Not found", which hides a data-type problem. If many rows come back as not found, check types and stray spaces.
A quick audit formula counts the fallback results:
=COUNTIF(F2:F100, "Not found")Summary
IFNA(value, value_if_na)replaces only#N/Aand passes every other error through.- It is the preferred wrapper for lookups, since missing keys give
#N/Awhile broken formulas give other errors. - The replacement you choose (
0,""or a message) changes how totals, averages and arithmetic behave. - Nest
IFNAfor fallback lookups,XLOOKUP's fourth argument for a built-in alternative, andISNAwhen you need a test rather than a value.
Exercise
A sheet uses =IFNA(VLOOKUP(E2, $A$2:$B$100, 2, FALSE), "Not found"). A colleague deletes column B, and every row now shows #REF! instead of "Not found". Explain why, and say what would have happened if the formula had used IFERROR.
Show answer
Deleting column B makes the lookup range invalid, so VLOOKUP returns #REF!. IFNA only replaces #N/A, so #REF! passes through and the problem is visible. With IFERROR, every row would show "Not found". The report would look normal while hiding the broken reference, so the fault could go unnoticed.
Exercise
Column F holds prices from a lookup wrapped in IFNA with a replacement of "". Cell G2 contains =F2*1.2. What does G2 show for a row where the lookup found nothing, and how could you change the formula in G2 to avoid that result?
Show answer
G2 shows #VALUE!, because F2 contains the text "" and arithmetic on text fails. Guard the calculation, for example =IF(F2="", "", F21.2), or use =IFERROR(F21.2, "") if you accept that it hides other errors too. The IF version is narrower and keeps real errors visible.
Exercise
Write a formula that looks up the code in E2 first in Sheet1!$A$2:$B$100 and then in Sheet2!$A$2:$B$100, returning the price from column 2 and the text "No price" when neither sheet has it. Say why IFNA is better than IFERROR here.
Show answer
=IFNA(VLOOKUP(E2, Sheet1!$A$2:$B$100, 2, FALSE), IFNA(VLOOKUP(E2, Sheet2!$A$2:$B$100, 2, FALSE), "No price")). IFNA only moves to the next source on #N/A, which means a missing key. A broken reference on either sheet gives #REF! and stays visible. IFERROR would swallow it and fall through to the next lookup or the message.