The XLOOKUP function
XLOOKUP is the modern replacement for VLOOKUP. You tell it where to look and where to return from as two separate ranges, so it can return values to the left as well as the right, and inserting a column never breaks it.
It does an exact match by default, and has a built-in argument for what to show when nothing is found.
=XLOOKUP(lookup_value, lookup_array, return_array, [if_not_found], [match_mode], [search_mode])
Arguments
- lookup_value
- What to look for, such as a name.
- lookup_array
- The single column (or row) to search.
- return_array
- The column (or row) to return a value from. It must be the same size as
lookup_array. - if_not_foundoptional
- What to show if there's no match, such as "Not found". Without it you get #N/A.
- match_modeoptional
- 0 (the default) for an exact match; -1 for exact or next smaller; 1 for exact or next larger; 2 for wildcards.
- search_modeoptional
- 1 (the default) searches from the top; -1 searches from the bottom, to find the last match.
Try it
=XLOOKUP(F2,B2:B6,D2:D6,"Not found") in G2. XLOOKUP finds Fatima Khan in the name column and returns the extension on the same row, 2314. Try typing a name that isn't listed.
G2
| A | B | C | D | E | F | G | H | |
|---|---|---|---|---|---|---|---|---|
| 1 | Staff ID | Name | Department | Extension | Name | Extension | ||
| 2 | S014 | Owen Price | Finance | 2201 | Fatima Khan | 2314 | ||
| 3 | S022 | Fatima Khan | HR | 2314 | ||||
| 4 | S031 | Liam Hughes | IT | 2420 | ||||
| 5 | S047 | Sophie Bell | Sales | 2108 | ||||
| 6 | S052 | Ravi Shah | IT | 2433 | ||||
| 7 | ||||||||
| 8 |
Edit the formula in G2, or change the data, and press Enter.
More examples
| Formula | Result | What it does |
|---|---|---|
| =XLOOKUP("Ravi Shah",B2:B6,A2:A6) | S052 | The return column is to the left of the names, which VLOOKUP can't do. |
| =XLOOKUP("Jo Evans",B2:B6,D2:D6,"Not found") | Not found | No match, so the if_not_found text is shown instead of #N/A. |
| =XLOOKUP("IT",C2:C6,B2:B6,,0,-1) | Ravi Shah | Searching from the bottom returns the last IT person, not the first. |
| =XLOOKUP(2400,D2:D6,B2:B6,,1) | Liam Hughes | Match mode 1: no extension is exactly 2400, so it takes the next larger, 2420. |
Tips
- XLOOKUP is in Excel for Microsoft 365, Excel 2021 and later. Files opened in Excel 2019 or earlier will show errors, so use INDEX with MATCH if you share with older versions.
- Lock both ranges with
$before copying the formula down. - The lookup and return ranges must have the same number of rows. Start and end them on the same rows.
Common mistakes
- #VALUE! appears.
lookup_arrayandreturn_arrayare different sizes, for exampleB2:B6andD1:D6. - #N/A for a name you can see.Usually a trailing space or a different spelling. TRIM the data, or wrap the lookup value:
TRIM(F2). - #NAME? appears.Your version of Excel doesn't have XLOOKUP. Use INDEX/MATCH or VLOOKUP instead.
In Google Sheets
Google Sheets added XLOOKUP in 2022 and it takes the same arguments, so formulas move between Sheets and current Excel unchanged.
Practise XLOOKUP with instant feedback
Type real formulas into a working spreadsheet and get told straight away whether they work.