Excel Lessons

MATCH vs XMATCH in Excel: find a position in a list

MATCH and XMATCH return where a value sits in a list, not the value. How they differ on exact match by default, searching from the end, and wildcards.

Published . 5 min read.

By Ali, Founder, Excel Lessons

MATCH and XMATCH both return where a value sits in a list, as a number. They do not return the value itself. The big difference is the default: XMATCH looks for an exact match, and MATCH does not.

XMATCH needs Excel 2021 or later, or Microsoft 365. It also works in Excel for the web. MATCH works in every version.

Here is a courier's delivery list for one day, in the order of the stops. Beside it is the price per box, which falls for bigger orders. Type both tables in A1 to E7.

Row A B C D E
1 CustomerBoxesFromPrice
2 Harbour Deli1204.00
3 Lotus Florist5103.50
4 Harbour Deli8253.00
5 Pine Hardware20502.50
6 Lotus Florist3
7 Grove Bakery15

Where they agree

Find Pine Hardware in the list. Both formulas give 4, because it is the 4th name in A2:A7.

=MATCH("Pine Hardware",A2:A7,0) gives 4.

=XMATCH("Pine Hardware",A2:A7) gives 4.

The position counts from the top of the range you give, not from row 1 of the sheet. Start the range at A1 and =MATCH("Pine Hardware",A1:A7,0) gives 5. The heading is now position 1.

Both ignore upper and lower case. =XMATCH("pine hardware",A2:A7) still gives 4. Both give #N/A for a name that is not in the list.

A position is useful when INDEX reads it. =INDEX(B2:B7,XMATCH("Pine Hardware",A2:A7)) gives 20, the boxes for Pine Hardware. The INDEX and MATCH article builds this step by step.

Difference 1: the default match

Notice the 0 at the end of the MATCH formula. Without it, MATCH uses match type 1. It assumes the list is sorted from small to large. Then it finds the largest value that is not bigger than yours.

XMATCH has no such default. Leave out the third part and it looks for an exact match.

On the price table in D2:D5, an order of 18 boxes shows the difference.

=MATCH(18,D2:D5) gives 2. There is no 18, so it takes the band that starts at 10.

=XMATCH(18,D2:D5) gives #N/A. There is no 18 exactly.

=XMATCH(18,D2:D5,-1) gives 2. Match mode -1 means "exact, or the next smaller value".

Then =INDEX(E2:E5,XMATCH(18,D2:D5,-1)) gives 3.5, the price per box for 18 boxes. Match mode 1 means "exact, or the next larger value", so =XMATCH(18,D2:D5,1) gives 3.

What goes wrong: a MATCH without the 0 on a list that is not sorted. The customer names are in stop order, not A to Z. MATCH still returns a position, but it may be the wrong one, and there is no error. This is a common bug in real files. Always type the 0 unless you want a band.

XMATCH with -1 or 1 does not need a sorted list. MATCH with 1 or -1 does. The approximate match article has more band tables.

Difference 2: searching from the end

Harbour Deli got 2 deliveries today. Both functions find the first one by default. Only XMATCH can find the last one.

=MATCH("Harbour Deli",A2:A7,0) gives 1, the first stop.

=XMATCH("Harbour Deli",A2:A7,0,-1) gives 3, the last stop.

The fourth part is the search mode. -1 means "start from the end". The position still counts from the top.

So =INDEX(B2:B7,XMATCH("Harbour Deli",A2:A7,0,-1)) gives 8, the boxes on the latest delivery. On a log that grows downwards, the last match is usually the one you want. MATCH has no simple way to do this.

Difference 3: wildcards

A star (*) stands for any text. MATCH with 0 treats the star as a wildcard. XMATCH treats it as a real star, unless you ask for wildcards.

=MATCH("Lotus*",A2:A7,0) gives 2.

=XMATCH("Lotus*",A2:A7) gives #N/A. No name is really "Lotus*".

=XMATCH("Lotus*",A2:A7,2) gives 2. Match mode 2 turns on wildcards.

This is safer than it looks. Say a product code has a star or a question mark in it. XMATCH finds it exactly as it is typed.

The differences in one table

MATCHXMATCH
Default matchSorted list, next smallerExact
Search from the endNoYes, search mode -1
Wildcards * and ?Yes, with 0Only with match mode 2
Needs a sorted listFor 1 and -1No
Excel versionsAllExcel 2021 and later, Microsoft 365

Which one to use

Use XMATCH, unless the file must open in Excel 2019 or older. Its default is the one you want most of the time. It can search from the end, and its bands do not need a sorted list.

If you use MATCH, always write the third part. Type 0 for an exact match. Type 1 only for a sorted band table, and say so in a note next to it. Somebody will sort that table one day.

Questions people ask

Why does MATCH return a number and not the name?

That is its job. MATCH says where, and INDEX says what is there. To get a value in one step, use XLOOKUP. The XLOOKUP vs VLOOKUP article compares them.

Can MATCH search a row instead of a column?

Yes, both can. Give them a range one row tall, such as B1:M1. The position then counts across, from the left.

Why do I get #N/A when the value is right there?

Usually one of the two is text and the other is a number. Or one has a space at the end. The cells look the same, so check with =LEN(A5).

The MATCH, XMATCH and INDEX lessons use their own sheets. Each lesson is a real sheet you type into, and each answer is checked when you press Enter.

Related articles