Sub topic 2
XLOOKUP syntax: the six arguments
This chapter assumes you can enter and copy formulas in Excel and that you understand cell references and ranges, including absolute references such as $E$2. You need Excel for Microsoft 365, Excel 2021 or later, or Excel for the web.
The shape of the function
XLOOKUP searches one range for a value and returns the item in the same position from another range. Its full form has six arguments. Only the first three are required.
=XLOOKUP(lookup_value, lookup_array, return_array, [if_not_found], [match_mode], [search_mode])Square brackets mark optional arguments. If you leave them out, Excel uses the defaults described below.
| Argument | Required | What it does | Default |
|---|---|---|---|
| `lookup_value` | Yes | The value to find | None |
| `lookup_array` | Yes | The range to search | None |
| `return_array` | Yes | The range to return a result from | None |
| `if_not_found` | No | The result to show when nothing matches | `#N/A` error |
| `match_mode` | No | How strictly to compare values | 0 (exact match) |
| `search_mode` | No | The order in which to search | 1 (first to last) |
The three required arguments
lookup_value is what you are looking for, usually a cell reference such as E2.
lookup_array is the single row or column that Excel searches. Excel looks for lookup_value here.
return_array is the range that holds the answers. Excel finds the position of the match in lookup_array, then returns the item at that same position in return_array.
Here is the simplest working formula. It looks for the value in E2 within A2:A10 and returns the value from the same position in C2:C10.
=XLOOKUP(E2, A2:A10, C2:C10)Suppose E2 matches the fourth cell of A2:A10, which is A5. The formula returns the fourth cell of C2:C10, which is C5.
The three optional arguments
Each optional argument changes one part of the behavior. You will use each in a later chapter, so this section only names them.
if_not_foundreplaces the#N/Aerror with text or a value you choose.match_modeswitches between exact, next smaller, next larger and wildcard matching.search_modesets the search direction, or asks Excel to use a binary search on sorted data.
To set a later optional argument, you must supply a value for the ones before it, or leave an empty slot with a comma. For example, to set only search_mode, write =XLOOKUP(E2, A2:A100, C2:C100, , 0, -1). Skipping if_not_found this way keeps the default #N/A behavior.
How the arguments fit together
The size of the two arrays matters. For a single-value result, lookup_array and return_array must have the same number of rows, if they are columns, or the same number of columns, if they are rows. If they differ, XLOOKUP returns #VALUE!.
The arrays do not need to sit next to each other, and the return array can be to the left of the lookup array. This is a difference from VLOOKUP, which can only return from columns to the right of the lookup column.
Use absolute references for ranges that should not move when you copy the formula down. In this version, the lookup value changes per row while both ranges stay fixed:
=XLOOKUP(E2, $A$2:$A$10, $C$2:$C$10)Copying it from E2 down to E3 changes the lookup value to E3 and leaves both ranges unchanged.
Check your understanding
Exercise
In =XLOOKUP(E2, A2:A10, C2:C10, "None", 0, -1), which argument supplies the text shown when there is no match, and which argument makes Excel search from the last item to the first?
Show answer
The fourth argument, "None", is ifnotfound and supplies the text for a missing value. The sixth argument, -1, is searchmode and searches from last to first. The fifth argument, 0, is matchmode and means exact match.
Exercise
A formula is =XLOOKUP(E2, A2:A10, C2:C11). It returns #VALUE!. What is the likely cause?
Show answer
The lookuparray has nine rows (A2:A10) but the returnarray has ten rows (C2:C11). The two arrays must be the same size, so change the return array to C2:C10.