- Purpose
- Find a value in one column or row and return the matching item from another column or row.
- Returns
- The matching value or values, or #N/A (or your own text) if nothing matches.
- Syntax
- Works in
- Excel 2021 and later · Microsoft 365 · Excel for the web · Google Sheets
Arguments
| Argument | Required | What it is |
|---|---|---|
| lookup_value | Yes | The value to search for. |
| lookup_array | Yes | The single column or single row to search. |
| return_array | Yes | The column or row to return from. It must be the same height (or width) as lookup_array, and it can sit on either side of it. |
| if_not_found | No | What to show when there is no match. Left out, the result is #N/A. |
| match_mode | No | 0 for an exact match (the default), -1 for exact or next smaller, 1 for exact or next larger, 2 for a wildcard match. |
| search_mode | No | 1 to search first to last (the default), -1 to search last to first, 2 or -2 for a binary search on sorted data. |
Example: find a name from a badge number
The badge number in E2 is searched for in column C. The name on the same row of column A is returned, even though column A is to the left of the search column.
| A | B | C | D | E | F | |
|---|---|---|---|---|---|---|
| 1 | Name | Team | Badge | Find badge | Name | |
| 2 | Priya Nair | Finance | B-2041 | B-3310 | Marta Ruiz | |
| 3 | Tom Becker | Sales | B-2187 | |||
| 4 | Marta Ruiz | Support | B-3310 | |||
| 5 | Chen Wei | Sales | B-3422 | |||
| 6 | Aisha Khan | Finance | B-4075 | |||
| 7 | Luca Rossi | Support | B-4190 |
Build your XLOOKUP formula
Fill in the fields with your own cells. The formula updates as you type.
Finds E2 in A2:A6 and returns the value at the same position in C2:C6. If nothing is found it shows "Not found".
Paste the formula into cell F2 or any empty cell. The coloured parts match the coloured fields. Using a different list separator? Replace the commas with semicolons.
How XLOOKUP works
XLOOKUP takes a value, searches for it in one column or one row, and returns the item at the same position in a second column or row. The search range and the return range are two separate arguments. That is the main difference from VLOOKUP, which takes one table and a column number.
Three things follow from that design:
- The return column can be to the left or right of the search column, or on another sheet.
- Inserting or deleting columns does not break the formula, because no column number is counted.
- The match is exact by default. You do not need to add FALSE or 0.
The fourth argument, if_not_found, replaces #N/A with text or a value of your choice, so you do not need to wrap the formula in IFERROR.
Match mode and search mode
The fifth argument sets what counts as a match.
| match_mode | Behaviour | Use it for |
|---|---|---|
0 or left out |
Exact match only. | Codes, names, IDs. |
-1 |
Exact match, or the next smaller value. | Bands such as tax rates, grades and commission tiers. |
1 |
Exact match, or the next larger value. | Finding the smallest size or tier that is big enough. |
2 |
Wildcard match, where * is any text and ? is one character. |
Partial text. |
Unlike VLOOKUP, the -1 and 1 modes do not need sorted data.
The sixth argument sets the direction of the search.
| search_mode | Behaviour |
|---|---|
1 or left out |
Search from the first item to the last. Returns the first match. |
-1 |
Search from the last item to the first. Returns the last match. |
2 |
Binary search. The lookup range must be sorted ascending. |
-2 |
Binary search. The lookup range must be sorted descending. |
A binary search on data that is not sorted returns wrong results without warning. Leave the argument out unless you have a reason to set it.
More examples
Find a band with the next smaller match
With score boundaries 0, 60, 70, 80, 90 in A2:A6 and grades F, D, C, B, A in B2:B6:
=XLOOKUP(84, A2:A6, B2:B6, , -1)
returns B, because 80 is the largest boundary that does not exceed 84.
Match part of a name
=XLOOKUP("*hub*", B2:B50, C2:C50, "Not found", 2)
returns the value in column C for the first row whose column B text contains “hub”.
Return the last match
=XLOOKUP(E2, A2:A100, C2:C100, , 0, -1)
returns the column C value for the lowest row that matches E2, which is the most recent entry in a log sorted by date.
Return a whole row
=XLOOKUP(E2, A2:A7, B2:D7)
returns the three cells from columns B to D on the matching row, spilled across three cells.
Look up a row and a column
=XLOOKUP(G1, A2:A6, XLOOKUP(G2, B1:D1, B2:D6))
The inner XLOOKUP picks the column whose header matches G2. The outer one returns the cell on the row that matches G1.
Tips
- Lock both ranges with dollar signs (
$A$2:$A$7) before copying the formula down. - The lookup and return ranges must be the same length. A mismatch returns #VALUE!.
- To skip an optional argument, leave it empty between the commas, as in
=XLOOKUP(E2, A2:A6, B2:B6, , -1). - XLOOKUP is not case-sensitive. “abc” and “ABC” match.
- A number and a text value that looks like a number do not match. Convert one side so both are the same type.
- XLOOKUP works across rows too. Pass a single row as the lookup range and another row as the return range, and it replaces HLOOKUP.
XLOOKUP or VLOOKUP
Use XLOOKUP when everyone who opens the file has Excel 2021, Microsoft 365 or Excel for the web. It needs fewer arguments for the common case, looks in either direction and survives inserted columns.
Use VLOOKUP or INDEX MATCH when the workbook must open in Excel 2019 or earlier. Those versions show #NAME? for every XLOOKUP formula. If you are not sure which version your readers have, INDEX MATCH gives you the same left and right lookups in every version of Excel.
You can build any of the three with the XLOOKUP generator, the VLOOKUP generator or the INDEX MATCH generator.
Errors and fixes
| Error | Why it happens | Fix |
|---|---|---|
| #N/A | No match was found and the if_not_found argument is empty. | Check for extra spaces and numbers stored as text, or add a fourth argument such as "Not found". |
| #VALUE! | The lookup array and the return array are different sizes, for example A2:A7 and C2:C9. | Make both ranges start and end on the same rows. |
| #NAME? | The workbook is open in Excel 2019 or earlier, which does not have XLOOKUP. | Open it in Excel 2021 or Microsoft 365, or rewrite the formula with VLOOKUP or INDEX and MATCH. |
| #SPILL! | The return array has several columns and the cells next to the formula are not empty. | Clear the cells the result needs, or return a single column. |
Questions
Why does XLOOKUP show #NAME?
The version of Excel that opened the file does not have the function. XLOOKUP exists in Excel 2021, Microsoft 365, Excel for the web and Google Sheets. Excel 2019 and earlier show #NAME?. A misspelled function name gives the same error.
Which Excel versions have XLOOKUP?
Excel 2021 and later, Microsoft 365 and Excel for the web. Google Sheets has it too. Excel 2019, 2016 and older versions do not, so use VLOOKUP or INDEX MATCH for files that must open there.
Is XLOOKUP exact match by default?
Yes. With no fifth argument XLOOKUP returns a result only for an identical value. This is the opposite of VLOOKUP, whose default is an approximate match.
Can XLOOKUP look to the left?
Yes. The search range and the return range are separate, so the return column can be on either side. =XLOOKUP(E2, C2:C7, A2:A7) searches column C and returns from column A.
Can XLOOKUP return more than one column?
Yes. Give it a return range that is several columns wide, such as =XLOOKUP(E2, A2:A7, B2:D7). The result spills into three cells side by side. It still returns one matching row. To return every matching row, use FILTER.
Can XLOOKUP use two criteria?
Yes. Multiply the tests together and look up the number 1: =XLOOKUP(1, (A2:A50=F1)*(B2:B50=F2), C2:C50). Each row scores 1 only when both tests are true.