Sub topic 11
Chaining Fallback Lookups
What you need first
This chapter assumes you can enter and copy formulas, use absolute references such as $A$2:$B$100, and write a basic VLOOKUP with IF. It also assumes you have read the earlier chapters on IFNA and IFERROR. Here you will put several lookups in a row, so that a failed search in one list triggers a search in the next.
The problem: one key, several lists
Real data is rarely in one place. A product code might be in the current price list, or, if it was retired, in a legacy list on another sheet. A customer ID might be in the regional table or in a head-office table.
A single IFNA handles one missing result:
=IFNA(VLOOKUP(E2, Sheet1!$A$2:$B$100, 2, FALSE), "Not found")If the code is missing from Sheet1, you get "Not found", even though Sheet2 may contain it. A chained fallback replaces the text with a second lookup. You show "Not found" only when every list has failed.
The basic pattern: nested IFNA
Put the next lookup in the second argument of IFNA:
=IFNA(VLOOKUP(E2, Sheet1!$A$2:$B$100, 2, FALSE), IFNA(VLOOKUP(E2, Sheet2!$A$2:$B$100, 2, FALSE), "Not found"))Excel works through it from the outside in:
- The outer
IFNAruns the Sheet1 lookup. - If that returns a value, the formula returns it and the rest is not needed.
- If it returns
#N/A, Excel uses the second argument, which is anotherIFNA. - That inner
IFNAruns the Sheet2 lookup. If it also returns#N/A, the text "Not found" is the result.
The last argument of the innermost IFNA is the final fallback. It is the only place where you choose a replacement value.
A worked example
Suppose Sheet1 holds current prices and Sheet2 holds retired items. The key column is E.
| Key in E | In Sheet1? | In Sheet2? | Result |
|---|---|---|---|
| A-100 | Yes (12.50) | No | 12.50 |
| B-200 | No | Yes (8.00) | 8.00 |
| C-300 | No | No | Not found |
| D-400 | Yes (20.00) | Yes (18.00) | 20.00 |
The last row shows that order sets priority. When the key exists in both lists, the first lookup wins and the second is never consulted. Put the most authoritative list first.
Why the chain needs IFNA, not IFERROR
You can build the same chain with IFERROR, and it will work until something breaks. The difference is what each function treats as "try the next list".
| Situation in the Sheet1 lookup | Chain with IFNA | Chain with IFERROR |
|---|---|---|
| Key not in the list (`#N/A`) | Goes to Sheet2 | Goes to Sheet2 |
| Sheet1 range was deleted (`#REF!`) | Shows `#REF!` | Silently goes to Sheet2 |
| Function name misspelled (`#NAME?`) | Shows `#NAME?` | Silently goes to Sheet2 |
| Key cell holds an error (`#VALUE!`) | Shows the error | Silently goes to Sheet2 |
With IFERROR, a broken first lookup looks like a normal miss. The formula quietly returns Sheet2 values, and the numbers look plausible. With IFNA, a broken lookup stays visible, and you fix it. A missing key is an expected result in a lookup chain. A #REF! is a bug.
Adding a third level
The pattern extends by nesting one more IFNA:
=IFNA(VLOOKUP(E2, Sheet1!$A$2:$B$100, 2, FALSE), IFNA(VLOOKUP(E2, Sheet2!$A$2:$B$100, 2, FALSE), IFNA(VLOOKUP(E2, Sheet3!$A$2:$B$100, 2, FALSE), "Not found")))Each level adds one IFNA( at the start and one closing parenthesis at the end. Count the closing parentheses when you edit these formulas. A missing one gives an error message from Excel, and an extra one is rejected as well.
Past three levels the formula gets hard to read. If you have Excel 2021 or Microsoft 365, LET lets you name the lookup key once:
=LET(key, E2, IFNA(VLOOKUP(key, Sheet1!$A$2:$B$100, 2, FALSE), IFNA(VLOOKUP(key, Sheet2!$A$2:$B$100, 2, FALSE), IFNA(VLOOKUP(key, Sheet3!$A$2:$B$100, 2, FALSE), "Not found"))))The result is the same. If the key later moves to another column, you change it in one place.
Chaining with XLOOKUP
XLOOKUP has a built-in fourth argument, if_not_found, which is returned only when no match exists. You can put another XLOOKUP there:
=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"))This has the same safety property as IFNA. Only a missing match triggers the fallback. A #REF! in the first lookup still shows. It also needs fewer functions, and you do not need a column index number, so you cannot get the index wrong.
Stacking the lists instead
If your lists share the same layout and you have Microsoft 365, VSTACK can combine them into one virtual table, so you need only one lookup:
=XLOOKUP(E2, VSTACK(Sheet1!$A$2:$A$100, Sheet2!$A$2:$A$100), VSTACK(Sheet1!$B$2:$B$100, Sheet2!$B$2:$B$100), "Not found")XLOOKUP searches from the first item to the last by default, so Sheet1 still has priority. Adding a third list means adding one more argument to each VSTACK rather than nesting another function. The drawback is availability. VSTACK does not exist in Excel 2019 or earlier, or in Excel 2021, so the file will show #NAME? for users on those versions.
Different lists, different columns
The lists in a chain do not have to share a layout. Each lookup is independent, so each can use its own range and column index:
=IFNA(VLOOKUP(E2, Sheet1!$A$2:$B$100, 2, FALSE), IFNA(VLOOKUP(E2, Sheet2!$C$2:$F$500, 3, FALSE), "Not found"))Here the second list starts in column C, so the key is in column C and the return value is the third column of that range, which is column E. Check each index against its own range. Copying the first lookup and changing only the sheet name is the most common source of wrong results.
Common mistakes
A chain that never moves on
VLOOKUP with the last argument set to TRUE, or with that argument left out, does an approximate match on sorted data. It often returns the closest smaller value instead of #N/A. The first lookup then "succeeds" with a wrong value, and the fallback never runs. Use FALSE (or 0) for exact matching in every link.
A chain that always ends in "Not found"
If the key exists but both lookups return #N/A, the keys probably differ in type or spacing. Typical causes are a number stored as text in one list, or a trailing space. No amount of chaining fixes this. Clean the data, for example by comparing TRIM(E2) or converting with VALUE. Check one case by hand with this formula:
=IF(ISNA(MATCH(E2, Sheet1!$A$2:$A$100, 0)), "Missing", "Found")Copying the formula without anchoring the ranges
Ranges such as Sheet2!A2:B100 shift down when you fill the formula down, and the lookup range loses its first rows. Use absolute references ($A$2:$B$100) for every range in every link.
A text fallback that breaks the totals
"Not found" is text. If the result column feeds a SUM, text is ignored. In a direct addition such as =H2+H3 or =H2*I2, text causes #VALUE!. If the column is used in arithmetic, decide whether a 0 or a blank is safer. The earlier chapters on replacement values explain the trade-offs. Remember that 0 can be mistaken for a real price.
Chaining where a table would do
Every link is another search of a list. On a few hundred rows this is fine. On tens of thousands of rows with several levels, recalculation slows noticeably, because a missing key searches every list. If you keep copying the same chain into many columns, consolidate the lists into one table with a column that marks the source, and use a single lookup.
Choosing an approach
| Need | Suggested approach |
|---|---|
| Two or three lists, any Excel version | Nested `IFNA` with `VLOOKUP` |
| Excel 2021 or Microsoft 365, a few lists | Nested `XLOOKUP` with `if_not_found` |
| Many lists with the same layout, Microsoft 365 | `XLOOKUP` over `VSTACK` ranges |
| Many lookups against the same lists | Merge the lists into one table |
Summary of the pattern
- Put the next lookup in the "value if #N/A" position of the previous
IFNA. - Use
IFNA, or theif_not_foundargument ofXLOOKUP, so only a missing key moves the chain on. - Order the lists by priority, because the first match ends the search.
- Use exact matching and absolute references in every link.
- Choose the last fallback value with the later formulas in mind.
Exercise
A worksheet uses this formula to find an employee's department: =IFERROR(VLOOKUP(A2, Sheet1!$A$2:$B$50, 2, FALSE), IFERROR(VLOOKUP(A2, Sheet2!$A$2:$B$50, 2, FALSE), "Unknown")). Someone deletes Sheet1, and the column now shows departments for many employees. Why is this a problem, and how would you rewrite the formula?
Show answer
After Sheet1 is deleted, the first lookup returns #REF!. IFERROR treats it like any other error and moves on to Sheet2, so employees who are only in the old Sheet1 list show "Unknown", and the formula gives no sign that anything broke. Rewrite it with IFNA so that #REF! is shown: =IFNA(VLOOKUP(A2, Sheet1!$A$2:$B$50, 2, FALSE), IFNA(VLOOKUP(A2, Sheet2!$A$2:$B$50, 2, FALSE), "Unknown")). Now a missing employee still falls through to Sheet2, and the deleted sheet shows #REF!, which you can find and fix.
Exercise
Write a formula that looks up the key in E2 in Sheet1 (keys in A2:A100, values in C2:C100) and then in Sheet2 (keys in A2:A100, values in C2:C100) using XLOOKUP, and returns "No match" if neither contains it. Which sheet wins if the key is in both?
Show answer
=XLOOKUP(E2, Sheet1!$A$2:$A$100, Sheet1!$C$2:$C$100, XLOOKUP(E2, Sheet2!$A$2:$A$100, Sheet2!$C$2:$C$100, "No match")). Sheet1 wins, because the Sheet2 lookup sits in the ifnotfound argument and runs only when Sheet1 has no match.
Exercise
A chained lookup returns a wrong price for a key that is in Sheet2 but not Sheet1, and it never reaches Sheet2. The first link is =VLOOKUP(E2, Sheet1!$A$2:$B$100, 2) with no fourth argument. What is the cause and the fix?
Show answer
When the fourth argument is omitted, VLOOKUP does an approximate match (the same as TRUE), which returns the closest smaller key in sorted data instead of #N/A. The first link therefore returns a value and the chain stops. Add FALSE to get an exact match: VLOOKUP(E2, Sheet1!$A$2:$B$100, 2, FALSE).