Example 1
Exact match is the default
B9 =XMATCH(A9,A2:A6)
Result: 4
No third argument is needed. MATCH would have run an approximate match here unless you typed 0.
B9 =XMATCH(A9,A2:A6) returns 4
Returns the position of a value in a row or column. It matches exactly by default and can search from the end, which makes it the modern MATCH.
Syntax
=XMATCH(, , , )
Excel for Microsoft 365 (Windows and Mac), Excel 2024, Excel 2021, Excel for the web, and Excel for iPad, iPhone and Android. Not available in Excel 2019 or earlier.
Try it
Edit the formula in B9 or change the inputs. The sheet recalculates as you type.
B9 =XMATCH(A9,A2:A6) returns 4
XMATCH returns the position of a value in a single row or column. It is the modern replacement for MATCH: the same idea, with safer defaults and two extra options. Positions count from 1 at the start of the range you give it, not from the top of the sheet.
0, is an exact match. -1 takes the exact match or, failing that, the next smaller item, and 1 takes the exact match or the next larger item. 2 turns on the wildcards *, ? and ~.1 searches top to bottom and returns the first match. -1 searches bottom to top and returns the last match. 2 and -2 run a binary search on sorted data.MATCH defaults to an approximate match (type 1), so forgetting its third argument can return a wrong position with no error. XMATCH defaults to an exact match, so =XMATCH(A9, A2:A20) does what most people expect.
XMATCH also fixes two limits of MATCH:
search_mode of -1 returns the position of the last match. With MATCH you needed a workaround for the last occurrence in a log or ledger.-1 and 1 don't need sorted data, because the default search checks every item. MATCH types 1 and -1 rely on sort order. The binary search modes 2 and -2 do need sorted data, and are only worth using on very large lists.Wildcards are an explicit choice: they work only with match_mode 2. With the default mode, an asterisk in the lookup value is just an asterisk.
XMATCH is mostly used with INDEX, which turns a position into a value: =INDEX(C2:C9, XMATCH(A12, A2:A9)). In current Excel that is rarely needed for a single lookup, because XLOOKUP does it in one step. XMATCH earns its place when you need the position itself, for example to find which column holds a header, to check whether a value appears in a list with ISNUMBER(XMATCH(...)), or to feed one position into several INDEX calls.
XMATCH needs Excel 2021, Excel 2024 or Microsoft 365. In Excel 2019 and earlier it returns #NAME?. If the file has to open there, use MATCH with 0 as the third argument.
#N/A means no match. A lookup range that is more than one row and column returns #VALUE!. A number stored as text doesn't match a real number: 1043 won't find "1043".
A9. Point at a cell rather than typing it.B2:B20. A range that is several rows and columns wide returns #VALUE!.0 exact match, the default. -1 exact match, or else the next smaller item. 1 exact match, or else the next larger item. 2 wildcard match, where * stands for any run of characters, ? for any one character, and ~ escapes them.1 searches from the first item to the last, the default. -1 searches from the last item to the first, so it returns the position of the last match. 2 runs a binary search on data sorted ascending. -2 runs a binary search on data sorted descending. The binary modes give wrong results on unsorted data.Each example is a live sheet. Change the inputs or the formula and watch the result.
Example 1
B9 =XMATCH(A9,A2:A6)
Result: 4
No third argument is needed. MATCH would have run an approximate match here unless you typed 0.
B9 =XMATCH(A9,A2:A6) returns 4
Example 2
E2 =XMATCH(D2,B2:B6,0,-1)
Result: 5
search_mode -1 starts at the bottom, so it returns 5, the position of the Friday visit. The default direction would return 1.
E2 =XMATCH(D2,B2:B6,0,-1) returns 5
Example 3
B9 =XMATCH(A9,A2:A6,1)
Result: 3
match_mode 1 returns the exact match or the next larger item. 3.2 kg isn't listed, so XMATCH returns the position of 5 kg.
B9 =XMATCH(A9,A2:A6,1) returns 3
Example 4
B10 =XMATCH(A10,A2:A6,2)
Result: 4
Train* matches any account that starts with Train. Without match_mode 2, the star would be read as a literal character and XMATCH would return #N/A.
B10 =XMATCH(A10,A2:A6,2) returns 4
Solve it in the sheet. Every answer is checked, with hints if you need them.
Task 1 of 2
In B9, return the position of the first delivery by the van in A9.
Answer in B9.
#NAME?. Use MATCH with 0 if the file has to open there.2. In the default mode Train* is searched as literal text.2 and -2 assume sorted data. On unsorted data they return wrong positions without an error, so leave search_mode at the default unless the list is sorted and very large.#N/A means no match. Check for trailing spaces and for numbers stored as text.XMATCH matches exactly by default, can search from the last item with search_mode -1, and does approximate matching without needing sorted data. MATCH defaults to an approximate match and works in every version of Excel.
Set search_mode to -1: `=XMATCH(D2, B2:B6, 0, -1)`. It searches from the bottom and returns the position of the last match.
No. It is available in Microsoft 365, Excel 2021, Excel 2024 and Excel for the web. In Excel 2019 and earlier it returns #NAME?.
Use XLOOKUP when you want a value back. Use XMATCH when you need the position itself, for example to find a header's column, to test whether a value is in a list, or to reuse one position in several INDEX formulas.
XMATCH is taught in Lookups and references, lesson 15: XMATCH: the modern MATCH. Each lesson is a short, graded exercise like the one above.