XLOOKUP Generator
Fill in the search column, the return column and the value to find, then copy a working XLOOKUP formula with a plain-English explanation underneath.
Updated
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 to use the generator
- Value to look up. Enter the cell that holds what you are searching for, such as a product code in
E2. - Column to search. Enter the single column, or single row, that contains the lookup values.
- Column to return. Enter the column that holds the answer. It must cover the same rows as the search column. It can sit to the left or the right of it.
- If nothing is found, show. Enter the text to display when there is no match. Clear the field to get #N/A instead.
- Match type. Leave it on exact match for codes, names and IDs.
- Select Copy and paste the formula into your sheet.
With the starting values the generator writes:
=XLOOKUP(E2, A2:A6, C2:C6, "Not found")
The six arguments of XLOOKUP
=XLOOKUP(lookup_value, lookup_array, return_array, [if_not_found], [match_mode], [search_mode])
| Argument | Meaning |
|---|---|
lookup_value |
What to search for. Usually a cell reference. |
lookup_array |
The one column or one row to search. |
return_array |
The range to return from. Same height as the lookup array for a vertical lookup. |
if_not_found |
Optional. What to show when there is no match. Without it the result is #N/A. |
match_mode |
Optional. 0 is an exact match and is the default. |
search_mode |
Optional. 1 searches from the first item to the last and is the default. |
The first three are required. The generator fills in the first five. Add the sixth by hand when you need it.
Match mode
| Value | Behaviour |
|---|---|
0 |
Exact match. The default. |
-1 |
Exact match, or the next smaller value. |
1 |
Exact match, or the next larger value. |
2 |
Wildcard match, where * is any text and ? is one character. |
Use -1 for banded lookups such as tax brackets, discount tiers and grade boundaries, where the table lists the lower limit of each band. Unlike VLOOKUP’s approximate match, the data does not have to be sorted.
Search mode
| Value | Behaviour |
|---|---|
1 |
First to last. The default. |
-1 |
Last to first. |
2 |
Binary search on data sorted in ascending order. |
-2 |
Binary search on data sorted in descending order. |
The binary modes are faster on very large sorted ranges and return wrong results on unsorted ones. Leave them alone unless you know the data is sorted.
Where XLOOKUP works
XLOOKUP is in Excel for Microsoft 365, Excel 2021 and later, Excel for the web, and Google Sheets. It is not in Excel 2019 or earlier. When someone opens your file in one of those versions, cells with XLOOKUP show #NAME? once they recalculate.
If the file will be shared with people on older versions, use VLOOKUP or INDEX and MATCH instead.
Looking to the left
VLOOKUP can only return a column to the right of the one it searches. XLOOKUP has no such rule, because the two ranges are given separately. To find a name in column C and return the ID from column A:
=XLOOKUP(E2, C2:C6, A2:A6)
Inserting or deleting a column between them does not break the formula either. Both ranges move with their data.
Returning several columns
Give a return range that is more than one column wide:
=XLOOKUP(E2, A2:A6, B2:D6)
One formula returns the values from columns B, C and D of the matching row. The results spill into the neighbouring cells to the right. If any of those cells already holds something, Excel shows #SPILL! until you clear it.
Finding the last match
By default XLOOKUP returns the first match from the top. For a log where the same customer or product appears many times and you want the most recent entry, search from the bottom:
=XLOOKUP(E2, A2:A6, C2:C6, "Not found", 0, -1)
The fifth argument, 0, keeps the match exact. The sixth, -1, reverses the search direction. Build the formula in the generator, then type , 0, -1 before the closing bracket.
Common mistakes
- Ranges of different sizes.
A2:A6paired withC2:C7returns #VALUE!. Both must cover the same rows. - Forgetting to lock the ranges. When you fill the formula down, the ranges shift with it. Lock them with dollar signs, as in
$A$2:$A$6, and leave the lookup value unlocked. Press F4 on a reference to add the dollar signs. - Numbers stored as text. The text “1001” does not match the number 1001. Make both sides the same type.
- Skipping an argument by position. To set match_mode without a not-found message, keep the comma for the empty argument:
=XLOOKUP(E2, A2:A6, C2:C6, , -1). The generator does this for you. - Hiding real problems with if_not_found. That argument only replaces #N/A. A #VALUE! or #NAME? error still shows, which is helpful: it points to a broken range or an unsupported version.
- Sharing with older Excel. Check which version your readers have before you build a workbook on XLOOKUP.
For the full reference with a worked example, see the XLOOKUP function page.
Questions
How do I use XLOOKUP?
Give it three things, in order: the value to find, the column to search, and the column to return. For example =XLOOKUP(E2, A2:A6, C2:C6) finds E2 in A2:A6 and returns the value from the same row of C2:C6.
Which versions of Excel have XLOOKUP?
Excel for Microsoft 365, Excel 2021 and later, and Excel for the web. Google Sheets has it too. Excel 2019, 2016 and earlier do not, and show #NAME? when they open a file that uses it.
What is the difference between XLOOKUP and VLOOKUP?
XLOOKUP takes the search column and the return column as two separate ranges, so it can look left and does not break when a column is inserted. It matches exactly by default and has its own not-found argument. VLOOKUP works in every version of Excel.
Can XLOOKUP return more than one column?
Yes. Make the return range several columns wide, for example =XLOOKUP(E2, A2:A6, B2:D6). The result spills into the cells to the right, which must be empty.
How do I find the last match instead of the first?
Set the sixth argument, search_mode, to -1. =XLOOKUP(E2, A2:A6, C2:C6, "Not found", 0, -1) searches from the bottom of the range upwards and returns the first match it meets.
Why does my XLOOKUP return #VALUE!?
The search range and the return range are different sizes. If one is A2:A6, the other must also cover rows 2 to 6. Check that both ranges start and end on the same rows.