Excel functions · Lookup
XLOOKUP function in Excel
XLOOKUP searches a range for a value and returns the matching item from another range, so you can pull a price, name or ID from a table by its key. It replaces VLOOKUP and HLOOKUP: it looks left or right, matches exactly by default, and lets you say what to show when nothing is found.
Last reviewed
Syntax
=XLOOKUP(lookup_value, lookup_array, return_array, [if_not_found], [match_mode], [search_mode])- lookup_valuerequired
- The value to find, such as a SKU or an employee ID.
- lookup_arrayrequired
- The single column or row to search.
- return_arrayrequired
- The column or row (or several columns) to return from. It must be the same height as lookup_array for a column, or the same width for a row.
- if_not_foundoptional
- What to return when there's no match, such as "Not found". Without it, XLOOKUP returns #N/A.
- match_modeoptional
- 0 exact match (the default), -1 exact or the next smaller item, 1 exact or the next larger item, 2 wildcard match with *, ? and ~.
- search_modeoptional
- 1 searches first to last (the default), -1 last to first, 2 binary search on data sorted ascending, -2 binary search on data sorted descending.
- Exact match is the default, unlike VLOOKUP, so you don't need a FALSE at the end.
- return_array can sit left of lookup_array, which VLOOKUP can't do.
- Give return_array several columns and the result spills across them.
- Matching ignores case: "p-104" finds "P-104".
Which versions have XLOOKUP
Microsoft 365, Excel for the web, and Excel 2021 or later (Windows and Mac). Not in Excel 2019 or 2016.
| Version | Has it |
|---|---|
| Microsoft 365 (Windows and Mac) | Yes |
| Excel for the web | Yes |
| Excel 2024 | Yes |
| Excel 2021 | Yes |
| Excel 2019 | No |
| Excel 2016 | No |
Google Sheets
Google Sheets has XLOOKUP with the same six arguments (search_key, lookup_range, result_range, missing_value, match_mode, search_mode), so most formulas work unchanged.
Examples
The examples use this sample sheet.
| Row | A | B | C | D |
|---|---|---|---|---|
| 1 | SKU | Product | Category | Price |
| 2 | P-101 | Desk lamp | Office | 24.50 |
| 3 | P-102 | Monitor stand | Office | 39.00 |
| 4 | P-103 | USB-C hub | Electronics | 45.00 |
| 5 | P-104 | Webcam | Electronics | 69.00 |
| 6 | P-105 | Desk chair | Furniture | 189.00 |
| 7 | P-106 | Footrest | Furniture | 32.00 |
1.Look up a price by SKU
=XLOOKUP("P-104", A2:A7, D2:D7)Result: 69.00
XLOOKUP finds P-104 in the SKU column and returns the price on the same row.
2.Look to the left
=XLOOKUP("Desk chair", B2:B7, A2:A7)Result: P-105
The SKU column is left of the product names. VLOOKUP can't return it; XLOOKUP can.
3.Show a message when the key is missing
=XLOOKUP("P-199", A2:A7, B2:B7, "Not found")Result: Not found
There's no P-199, so XLOOKUP returns the if_not_found text instead of #N/A.
Common errors and fixes
| Error | Why it happens | Fix |
|---|---|---|
| #N/A | The value isn't in lookup_array, often because of a trailing space or a number stored as text. | Add an if_not_found value, clean the keys with TRIM, or convert text numbers with VALUE. |
| #VALUE! | lookup_array and return_array are different sizes, for example A2:A7 and D2:D8. | Make both ranges cover the same rows. |
| #NAME? | Your Excel doesn't have XLOOKUP (Excel 2019 or older), or the name is misspelled. | Use INDEX with MATCH, or open the file in Microsoft 365 or Excel 2021 or later. |
| #SPILL! | return_array has several columns and cells to the right of the formula aren't empty. | Clear the cells the result needs to spill into. |
Do it with GPTExcel
Skip writing XLOOKUP by hand
Upload your Excel or CSV file to Chat and ask in plain English. GPTExcel writes the formula for your file and your version of Excel or Google Sheets.
Add a Price column to my Orders sheet by looking up each SKU in the Products sheet.
Done. I used XLOOKUP on your sheet and checked the results against your data.
- Written for your platform and version
- Checked against your actual data
- Newest functions looked up in official docs
XLOOKUP questions
- Is XLOOKUP better than VLOOKUP?
- For most lookups, yes. XLOOKUP matches exactly by default, can return a column to the left, doesn't break when you insert columns, and has a built-in if_not_found value. VLOOKUP is still useful when a file must open in Excel 2019 or older.
- Does XLOOKUP work in Google Sheets?
- Yes. Google Sheets has XLOOKUP with the same six arguments, so a formula like =XLOOKUP("P-104", A2:A7, D2:D7) works in both.
- Why does XLOOKUP show #NAME?
- #NAME? usually means the Excel you're using doesn't have XLOOKUP. It's in Microsoft 365, Excel for the web, and Excel 2021 and later; Excel 2019 and 2016 need INDEX with MATCH instead.
Skip the formula hunt
Upload a spreadsheet and ask in plain English. Free plan, no credit card.
Start free