Sub topic 12
Built-in handling with XLOOKUP
This chapter assumes you can enter and copy formulas, use relative and absolute references, and write a basic VLOOKUP. You should also know how IFNA and IFERROR differ. Earlier chapters covered both. Here you will see how XLOOKUP makes the IFNA(VLOOKUP(...)) pattern unnecessary for the most common case, and where that built-in handling stops.
Why XLOOKUP has error handling built in
Most lookup formulas that need error handling fail for one reason: the lookup value is not in the list. With VLOOKUP, that produces #N/A, so you wrap the formula:
=IFNA(VLOOKUP(E2, $A$2:$B$100, 2, FALSE), "Not found")XLOOKUP takes the fallback as its fourth argument, if_not_found:
=XLOOKUP(E2, $A$2:$A$100, $B$2:$B$100, "Not found")The formula reads as one unit. There is no outer function to balance, and the fallback sits next to the arguments it belongs to.
XLOOKUP is available in Excel for Microsoft 365, Excel 2021 and later, and Excel for the web. It does not exist in Excel 2019 or earlier. If a workbook must open in those versions, keep the IFNA(VLOOKUP(...)) or IFNA(INDEX(...MATCH...)) pattern.
The full syntax
=XLOOKUP(lookup_value, lookup_array, return_array, [if_not_found], [match_mode], [search_mode])| Argument | Role |
|---|---|
| `lookup_value` | The value to find. |
| `lookup_array` | The single row or column to search. |
| `return_array` | The row or column to return from. It must have the same size as `lookup_array`. |
| `if_not_found` | What to return when no match exists. Optional. |
| `match_mode` | 0 for exact (the default), -1 or 1 for the next smaller or larger item, 2 for wildcards. |
| `search_mode` | Search direction, or binary search. |
Two differences from VLOOKUP matter for error handling:
- The default match mode is exact. You do not need the
FALSEargument thatVLOOKUPrequires to avoid approximate matching. - You point at the return column directly. Inserting a column in the table cannot silently shift a column index number, so there is one less source of wrong results.
What if_not_found catches
if_not_found triggers in exactly one situation: the search completed and found no match. It behaves like IFNA, not IFERROR. The next sections cover that distinction.
Sorry, I need to give the diagram in the required fence format. Here is the chapter in full.
Built-in handling with XLOOKUP
This chapter assumes you can enter and copy formulas, use relative and absolute references, and write a basic VLOOKUP. It also assumes you know how IFERROR and IFNA differ, which earlier chapters covered. Here you will see how XLOOKUP makes the IFNA(VLOOKUP(...)) pattern unnecessary for the most common case, and where its built-in handling stops.
Why XLOOKUP has error handling built in
Most lookup formulas that need error handling fail for one reason: the lookup value is not in the list. With VLOOKUP, a missing value produces #N/A, so you wrap the formula:
=IFNA(VLOOKUP(E2, $A$2:$B$100, 2, FALSE), "Not found")XLOOKUP takes the fallback as its fourth argument, if_not_found:
=XLOOKUP(E2, $A$2:$A$100, $B$2:$B$100, "Not found")The formula is one unit. There is no outer function to balance, and the fallback sits next to the arguments it belongs to.
XLOOKUP is available in Microsoft 365, Excel 2021 and later, and Excel for the web. It does not exist in Excel 2019 or earlier. If a workbook must open in those versions, keep the IFNA(VLOOKUP(...)) pattern or use IFNA with INDEX and MATCH.
The full syntax
=XLOOKUP(lookup_value, lookup_array, return_array, [if_not_found], [match_mode], [search_mode])| Argument | Role |
|---|---|
| `lookup_value` | The value to find. |
| `lookup_array` | The single row or column to search. |
| `return_array` | The row or column to return from. It must be the same size as `lookup_array`. |
| `if_not_found` | What to return when no match exists. Optional. |
| `match_mode` | 0 for exact (the default), -1 or 1 for the next smaller or larger item, 2 for wildcards. |
| `search_mode` | The search direction, or a binary search. |
Two differences from VLOOKUP matter for error handling:
- The default match mode is exact. You do not need the
FALSEargument thatVLOOKUPrequires to avoid approximate matching. - You point at the return column directly. Inserting a column in the table cannot shift a column index number, so one source of wrong results disappears.
What if_not_found catches
if_not_found applies in exactly one situation: the search finished and found no match. In that respect it behaves like IFNA, not IFERROR. Anything else that goes wrong still reaches the cell as an error.
The cases below use a price list in A2:B100, with E2 holding the product ID to find:
| Situation | Result of `XLOOKUP(E2, $A$2:$A$100, $B$2:$B$100, "Not found")` |
|---|---|
| ID exists and its price is 12.50 | 12.5 |
| ID does not exist | Not found |
| ID exists but its price cell is empty | 0 |
| ID exists but its price cell holds `#DIV/0!` | `#DIV/0!` |
| `return_array` has a different size than `lookup_array` | `#VALUE!` |
The last three rows are the important ones. A matched cell is returned as it is, so an error stored in the return column is not replaced. That is usually what you want, because a bad price is a real problem and should stay visible. An empty return cell comes back as 0, not blank, which can mislead if zero is a meaningful price.
Choosing the fallback value
The fourth argument can be a number, text, a cell reference, or another formula. The same trade-offs from the earlier chapter on replacement values apply.
=XLOOKUP(E2, $A$2:$A$100, $B$2:$B$100, 0)Returning 0 keeps the column numeric, so SUM and arithmetic keep working. It also makes "missing" indistinguishable from a real zero.
=XLOOKUP(E2, $A$2:$A$100, $B$2:$B$100, "Not found")Returning text makes missing rows easy to spot. SUM ignores text, but + and * on that cell produce #VALUE!. Use a text fallback only where the result is for reading, not for further arithmetic.
=XLOOKUP(E2, $A$2:$A$100, $B$2:$B$100, "")An empty string looks blank but is text, not an empty cell. The pitfalls are the same as with IFERROR(..., ""): ISBLANK returns FALSE and arithmetic on the cell fails.
You can also point the fallback at a cell, such as $H$1, and keep the message in one place. Changing the wording then needs one edit instead of a find and replace across formulas.
Omitting the argument
If you leave out if_not_found, a missing value returns #N/A, the same as VLOOKUP. That is sometimes the right choice. In a column that feeds a chart, #N/A makes Excel skip the point instead of plotting a zero. In a column that feeds a review step, a visible #N/A forces someone to look.
Chained fallbacks with XLOOKUP
An earlier chapter showed a chain of IFNA(VLOOKUP(...)) calls that searches a second sheet when the first fails. With XLOOKUP, a second XLOOKUP becomes the if_not_found argument:
=XLOOKUP(E2, Sheet1!$A$2:$A$100, Sheet1!$B$2:$B$100,
XLOOKUP(E2, Sheet2!$A$2:$A$100, Sheet2!$B$2:$B$100, "Not found"))Read it from the inside out. The inner formula searches Sheet2 and returns "Not found" only if both sheets fail. The line break after the first comma is only for readability, and Excel accepts it in the formula bar. Compare the IFNA version:
=IFNA(VLOOKUP(E2, Sheet1!$A$2:$B$100, 2, FALSE), IFNA(VLOOKUP(E2, Sheet2!$A$2:$B$100, 2, FALSE), "Not found"))The XLOOKUP form has fewer closing parentheses and no column index numbers. Both forms get hard to maintain beyond two or three sources. If you need more, consider combining the sources into one table with Power Query instead.
Where built-in handling is not enough
if_not_found only helps with a missing match. Several other failures need different tools.
Errors from bad arguments
If lookup_array and return_array differ in size, you get #VALUE!. If a referenced sheet or column was deleted, you get #REF!. Neither is a missing match, so the fallback does not appear. That is deliberate: these are mistakes in the workbook, not gaps in the data.
You could wrap the whole formula in IFERROR:
=IFERROR(XLOOKUP(E2, $A$2:$A$100, $B$2:$B$100, "Not found"), "Not found")This works but throws away the benefit. Every error now looks like a missing ID, including a deleted range. Avoid it unless you have a specific reason.
Matches that look wrong
Many "not found" results are data problems. Typical causes:
- The ID in
E2has a trailing space, so"A101 "does not equal"A101". - One list stores IDs as numbers and the other as text, so
101does not equal"101". - The lookup range was not anchored with
$, so it shifted when you copied the formula down.
A friendly fallback message hides these. When a large share of rows say "Not found", test a few by hand before accepting the result. =LEN(E2) against the length you expect, and =ISNUMBER(E2), find the first two problems quickly.
Errors inside the data
Because a matched cell is returned unchanged, an error in the source column reaches your result. If you want that case handled as well, wrap the formula in IFERROR, and accept that you now lose the distinction:
=IFERROR(XLOOKUP(E2, $A$2:$A$100, $B$2:$B$100, "Not found"), "Check source")Here the two messages differ. "Not found" means no match, and "Check source" means something else went wrong. This keeps the two causes separate, which a single IFERROR fallback cannot do.
Checking before you look up
Sometimes you do not want the value at all, only to know whether it exists. The test from the earlier chapter on preventive checks works with any lookup:
=IF(ISNA(MATCH(E2, $A$2:$A$100, 0)), "Missing", "Found")MATCH with match type 0 does an exact search and returns #N/A when nothing matches. ISNA turns that into TRUE or FALSE. Only #N/A is tested, so a #REF! in the range still appears.
COUNTIF also works for this check, and it never returns an error for a missing value:
=IF(COUNTIF($A$2:$A$100, E2) = 0, "Missing", "Found")Note that COUNTIF treats wildcard characters and comparison operators in the lookup value as patterns. An ID such as A* would match many items. For IDs that may contain *, ? or ~, the MATCH form is safer.
If you need the position of the match, use XMATCH. It has the same exact default as XLOOKUP and returns #N/A for a missing value, which you can test with ISNA.
Which approach to use
| Need | Suggested formula |
|---|---|
| Lookup with a message for missing items, Excel 2021 or later | `XLOOKUP` with `if_not_found` |
| Same lookup, workbook shared with older Excel | `IFNA(VLOOKUP(...), "Not found")` |
| Fallback to a second list | Nested `XLOOKUP` in `if_not_found` |
| Only check whether an item exists | `IF(ISNA(MATCH(...)), ...)` or `COUNTIF` |
| Also handle errors stored in the return column | `IFERROR` around `XLOOKUP`, with a distinct message |
| Keep `#N/A` so a chart skips the point | Omit `if_not_found` |
Exercises
Exercise
A price list in A2:B100 holds product IDs and prices. Write a formula for F2 that returns the price for the ID in E2, shows "No such product" when the ID is missing, and still shows #REF! if someone deletes the price column.
Show answer
=XLOOKUP(E2, $A$2:$A$100, $B$2:$B$100, "No such product") The fourth argument handles only the missing-match case. A deleted price column makes return_array invalid, so the #REF! error is still returned. Wrapping the formula in IFERROR would hide it.
Exercise
In the formula =XLOOKUP(E2, $A$2:$A$100, $B$2:$B$100, "Not found"), the matched row's price cell contains #DIV/0!. What does the formula return, and why?
Show answer
It returns #DIV/0!. The ifnotfound argument applies only when no match is found. A match was found, so XLOOKUP returns the matched cell as it is, including the error stored in it.
Exercise
Extend the formula so a missing ID is searched for in Archive!A2:B500 (IDs in column A, prices in column B) before returning "Not found". Use XLOOKUP only.
Show answer
=XLOOKUP(E2, $A$2:$A$100, $B$2:$B$100, XLOOKUP(E2, Archive!$A$2:$A$500, Archive!$B$2:$B$500, "Not found")) The inner XLOOKUP is the ifnotfound value of the outer one, so it runs only when the first list has no match.