XMATCH Function in Excel: Find a Position
By ExcelReady TeamUpdated 6 min read
The short answer
XMATCH returns the position of a value in a row or column. Write =XMATCH(lookup_value, lookup_array): =XMATCH("Omar",B2:B7) returns 2 if Omar is the second item. It does an exact match by default, can match the next smaller or larger value, supports wildcards and can search from the bottom up. It needs Excel 2021 or Microsoft 365.
Key takeaways
- XMATCH returns a position (a number), not the value itself.
- It defaults to an exact match, so you don't need to type 0 like you do with MATCH.
- match_mode: 0 exact, -1 exact or next smaller, 1 exact or next larger, 2 wildcard.
- search_mode -1 searches from the bottom, which finds the last occurrence.
- Pair XMATCH with INDEX to return a value from any column.
On this page+
The XMATCH function in Excel finds a value in a list and returns its position, such as 2 for the second item. It is the modern version of MATCH: it does an exact match by default, can search from the bottom up, and understands wildcards. This guide shows each option on one small order list, and how to combine XMATCH with INDEX to return a value.
XMATCH needs Excel 2021, Excel 2024, Microsoft 365 or Excel for the web. In older versions, use MATCH instead.
What does XMATCH return?#
XMATCH returns a position, not a value. If you ask where "Omar" is in a list of names and he is second, XMATCH returns 2. On its own, that number answers questions like "which row is this in?" or "is this value in the list at all?". Combined with INDEX, it becomes a full lookup.
The syntax has two required parts and two optional ones:
=XMATCH(lookup_value, lookup_array, [match_mode], [search_mode])| Part | What it means | Default |
|---|---|---|
| lookup_value | The value to find | |
| lookup_array | One row or one column to search | |
| match_mode | 0 exact, -1 exact or next smaller, 1 exact or next larger, 2 wildcard | 0 |
| search_mode | 1 first to last, -1 last to first, 2 or -2 binary search on sorted data | 1 |
All the examples use this order list in A1:C7:
| A | B | C | |
|---|---|---|---|
| 1 | Order | Customer | Amount |
| 2 | 1001 | Lena | 250 |
| 3 | 1002 | Omar | 120 |
| 4 | 1003 | Lena | 310 |
| 5 | 1004 | Ravi | 95 |
| 6 | 1005 | Omar | 410 |
| 7 | 1006 | Lena | 180 |
How to find a position with XMATCH#
For a basic exact match, give XMATCH the value and the range:
=XMATCH("Omar",B2:B7)The result is 2. Omar is in B3, which is the second cell of B2:B7. The count starts at the first cell of the range, not at row 1 of the sheet.
XMATCH returns the first match it finds, so Omar's second order in B6 is ignored. If the value isn't in the list, the result is #N/A. That makes XMATCH a quick way to check membership: =ISNUMBER(XMATCH("Ravi",B2:B7)) returns TRUE if Ravi is in the list.
XMATCH is not case-sensitive, so "omar" finds "Omar" too.
XMATCH can also look up several values at once. =XMATCH({"Ravi","Omar"},B2:B7) returns 4 and 2, spilled into two cells side by side. Point the first argument at a range of names instead, and you get one position per name.
How to find the last match with search_mode -1#
Set search_mode to -1 to search from the bottom up. This finds the last occurrence, such as a customer's most recent order:
=XMATCH("Lena",B2:B7,0,-1)The result is 6. Even though XMATCH started at the bottom, the position is still counted from the top: Lena's last order is the sixth row of the range. The 0 keeps the match exact. You must type it, because search_mode is the fourth argument and match_mode sits before it.
The guide to looking up the last match shows more ways to do this, including in older Excel.
Next smaller, next larger and wildcard matches#
match_mode controls what counts as a match when the exact value isn't there.
| Formula | What it asks | Result |
|---|---|---|
=XMATCH(300,C2:C7,1) | Position of 300, or the next larger amount | 3 (310) |
=XMATCH(300,C2:C7,-1) | Position of 300, or the next smaller amount | 1 (250) |
=XMATCH("R*",B2:B7,2) | First name starting with R | 4 (Ravi) |
The amounts in column C aren't sorted, and that's fine. XMATCH's next smaller and next larger modes find the closest value anywhere in the list. MATCH is stricter: its types 1 and -1 need sorted data, as explained in MATCH type 0 vs 1 vs -1.
In wildcard mode, * stands for any number of characters, ? for exactly one, and ~ lets you search for a real asterisk or question mark. Wildcards only work when match_mode is 2.
How to use XMATCH with INDEX#
XMATCH finds the row, and INDEX returns the value from that row in another column. To get the amount of Lena's last order:
=INDEX(C2:C7,XMATCH("Lena",B2:B7,0,-1))XMATCH returns 6, and the sixth value of C2:C7 is 180. Both ranges must start on the same row, or INDEX will pick the wrong cell.
For a two-way lookup, use one XMATCH for the row and another for the column: =INDEX(A2:C7,XMATCH(1004,A2:A7),XMATCH("Amount",A1:C1)) returns 95. The INDEX MATCH guide explains this pattern step by step, and it extends to lookups with multiple criteria.
XMATCH vs MATCH: what changed#
XMATCH fixes the main traps in MATCH:
| XMATCH | MATCH | |
|---|---|---|
| Default match | Exact | Approximate (type 1) |
| Search from the bottom | Yes, search_mode -1 | No |
| Next larger on unsorted data | Yes | No, needs descending sort |
| Wildcards | match_mode 2 | Type 0 |
| Works in | Excel 2021, 2024, Microsoft 365 | Every version |
Forgetting the 0 in MATCH is a classic mistake that gives wrong answers with no error. XMATCH avoids it. For a full side-by-side, read MATCH vs XMATCH, and for MATCH on its own see the MATCH function in Excel and the MATCH function guide.
Common XMATCH mistakes#
- Using a range with several columns. XMATCH searches one row or one column.
B2:C7returns #VALUE!. - Skipping match_mode when setting search_mode.
=XMATCH("Lena",B2:B7,-1)sets match_mode to -1, not search_mode. Write0,-1. - Expecting a value instead of a position. If you want the amount, wrap XMATCH in INDEX.
- Sharing the file with older Excel. Anyone on Excel 2019 or earlier sees #NAME?. Use MATCH with 0 if the file must work everywhere.
Practise it#
Positions click once you've counted them yourself on a real list. Practise XLOOKUP and XMATCH match modes in a live spreadsheet: you type the formula and it checks the result instantly. Then practise INDEX and MATCH to turn positions into full lookups.
Try it yourself
This is a live spreadsheet. Type the formula in the green cell and press Enter.
Lena appears three times. In E2, use XMATCH to find the position of her last order in B2:B7: exact match (0) and search from the bottom (-1).
| A | B | C | D | E | F | |
|---|---|---|---|---|---|---|
| 1 | Amount | Last Lena | ||||
| 2 | ||||||
| 3 | ||||||
| 4 | ||||||
| 5 | ||||||
| 6 | ||||||
| 7 | ||||||
| 8 | ||||||
| 9 | ||||||
| 10 |
Tip: Four arguments: "Lena", the range B2:B7, 0 for exact, and -1 to search from the last row up.
Practise this in a lesson
Frequently asked questions
What does XMATCH do in Excel?
XMATCH finds a value in a row or column and returns its position as a number. For example, if Omar is the second name in a list, =XMATCH("Omar",B2:B7) returns 2.
What is the difference between MATCH and XMATCH?
XMATCH defaults to an exact match, can search from the bottom up, and its next smaller and next larger modes work on unsorted data. MATCH defaults to an approximate match and works in every Excel version.
Which Excel versions have XMATCH?
XMATCH is available in Excel 2021, Excel 2024, Microsoft 365 and Excel for the web. In older versions it shows #NAME?.
How do I find the last occurrence with XMATCH?
Set the fourth argument, search_mode, to -1. =XMATCH("Lena",B2:B7,0,-1) searches from the bottom and returns the position of the last Lena, still counted from the top.