What is the XMATCH function?
=XMATCH(lookup_value, lookup_array, [match_mode], [search_mode])XMATCH returns the position of a value in a range. It is the newer version of MATCH, and when omitted it looks for an exact match.
It supports searching from the bottom (search_mode -1), approximate matches that need no sorting, and wildcards. Watch the range compared cell by cell above.
Arguments
- lookup_value
- The value to find in the range.
- lookup_array
- The column or row to search.
- match_mode
- 0 (omitted) exact; -1 next smaller if none; 1 next larger if none; 2 wildcard.
- search_mode
- 1 (omitted) from first to last; -1 from last to first.
XMATCH examples
Example 1. Find a position
=XMATCH("Eggs", B2:B9)4.
Example 2. With INDEX
=INDEX(C2:C9, XMATCH("Eggs", B2:B9))Returns the price of Eggs, 6900.
Example 3. Wildcard
=XMATCH("?ilk", B2:B9, 2)The position of "Milk", 2.
Common mistakes
Assuming the same default as MATCH
MATCH defaults to 1 (approximate match), but XMATCH defaults to 0 (exact match).
Opening in older Excel
Excel 2019 and earlier have no XMATCH, so you get #NAME?.
FAQ
- Is the result a row number?
- No. It is the position within the range; the first cell of B2:B9 is 1.
- What if it is not found?
- You get #N/A. You can wrap it in IFERROR.