Field Guide

The MATCH function in Excel: how it finds a position

Updated

The MATCH function returns the position of a value within a row or column, not the value itself. Its syntax is MATCH(lookup_value, lookup_array, [match_type]): the value to find, the single column or row to search, and how to match. So =MATCH(40, B2:B5, 0) returns 3 when 40 is the third number in B2:B5, the position counted from the top of that range.

On its own, MATCH gives you a number, so it is usually paired with a function that takes a position, most often INDEX. That pairing, the INDEX and MATCH combo, has its own guide. This page stays on MATCH standing alone: how the match_type changes what it finds, how wildcards work, and how XMATCH, the newer Microsoft 365 version, improves on it.

What does the MATCH function do?

MATCH searches a single column or row for a value and reports where it sits, as a number counted from the start of that range. Here a list of products runs down column A, and MATCH finds where one of them lands:

C2
fx
=MATCH(B2, A2:A5, 0)
A B C
1 Item Find item Position
2 Apples Cherries 3
3 Bananas
4 Cherries
5 Dates
MATCH searches A2:A5 for Cherries, the value in B2. Cherries is the third entry counted from the top of that range, so MATCH returns 3, the position, not the word. It sits in worksheet row 4, but the count starts at the top of the array, A2.

Two things are worth pinning down here. First, the answer is a position, not the matched value: MATCH gives back 3, not Cherries. Second, that position is counted from the top of the array you searched, not the worksheet row number. Cherries sits in worksheet row 4, but it is the third cell of A2:A5, so the position is 3. To turn that number into a value you nest MATCH inside INDEX, which is the whole reason the INDEX and MATCH combo exists.

What does the match_type argument do?

The third argument, match_type, is optional and it is where most MATCH trouble starts. It takes one of three values:

match_type What MATCH finds Sort order the array needs
1 or omitted the largest value less than or equal to lookup_value ascending
0 the first value exactly equal to lookup_value any order
-1 the smallest value greater than or equal to lookup_value descending

Most of the time you want 0, an exact match:

=MATCH(B2, A2:A5, 0)
The 0 is the match_type, and it asks for an exact match: MATCH returns the position of the first entry exactly equal to B2, in a range in any order. Leave it off and MATCH switches to an approximate match instead, which is where the surprises come from.

The trap is that leaving match_type off does not give you an exact match. It gives you 1, an approximate match that expects the range sorted in ascending order and returns the largest value at or below the one you asked for:

C2
fx
=MATCH(B2, A2:A5, 1)
A B C
1 Min score Find Position
2 0 75 3
3 60
4 70
5 85
With match_type 1, MATCH finds the largest band value less than or equal to 75. The bands are sorted ascending, so it settles on 70, the third entry, and returns 3. On an unsorted list this approximate mode can return a plausible wrong position rather than an error.

That behavior is genuinely useful for banded lookups like tax brackets or grade boundaries, where you want the nearest value at or below the input. The problem is the silent version: reach for MATCH to find an exact ID, forget the 0, and on an unsorted list MATCH can hand back a position that looks right and is not. Write the 0 unless you specifically want the approximate mode. The mirror value, -1, does the same job upside down: it finds the smallest value greater than or equal to the lookup and needs the range sorted descending.

MATCH is also case-insensitive, so it treats a capital and a lowercase letter as the same when matching text.

Matching text with wildcards

When match_type is 0 and the lookup value is text, MATCH accepts two wildcard characters:

=MATCH("North*", A2:A5, 0)
With match_type 0 and a text lookup value, an asterisk stands for any run of characters, so North followed by an asterisk matches North, Northeast, and Northwest alike. A question mark stands for a single character. Put a tilde before either symbol to match it literally.

An asterisk matches any sequence of characters and a question mark matches exactly one, so wildcards are handy when you know the start of a label but not the rest. To search for an actual question mark or asterisk, type a tilde ahead of it.

What is XMATCH, and how is it different from MATCH?

XMATCH is the modern version of MATCH, and Microsoft points you at it from the MATCH page itself: “Try using the new XMATCH function, an improved version of MATCH that works in any direction and returns exact matches by default, making it easier and more convenient to use than its predecessor.” Like MATCH, it returns a position; the difference is in the defaults and the extra control.

fx
=XMATCH(lookup_value, lookup_array, [match_mode], [search_mode])

The first two arguments are the same as MATCH. The two optional ones are where XMATCH pulls ahead:

The search_mode of -1 is the one MATCH cannot do at all. It scans from the bottom up, so when a value appears more than once, XMATCH returns the last one instead of the first:

C2
fx
=XMATCH(B2, A2:A5, 0, -1)
A B C
1 Status Find Position
2 Open Open 4
3 Closed
4 Open
5 Open
XMATCH searches A2:A5 for Open. The fourth argument, search_mode -1, scans from the bottom up, so it lands on the last Open, at position 4. The default first-to-last search would return the first, position 1. The third argument, 0, keeps the match exact.

XMATCH is XLOOKUP’s position-finding sibling: XLOOKUP returns the value at a match, XMATCH returns its position, and both share the same match and search modes. The full retrieval story is in the XLOOKUP guide.

On availability, XMATCH follows XLOOKUP exactly. It is in Excel for Microsoft 365, Excel 2021, Excel 2024, and later, and it is not in Excel 2016 or Excel 2019. Open an XMATCH formula in one of those older versions and it shows a #NAME? error, so plain MATCH remains the choice for a workbook that has to run everywhere.

MATCH on its own vs INDEX and MATCH

It helps to keep the two straight. MATCH alone answers where a value is, as a number. The INDEX and MATCH combo takes that number and answers what value sits at that position, by nesting the MATCH inside INDEX. This page owns the standalone function; the combined lookup, including left lookups and multiple criteria, is covered in its own guide.

Why does MATCH return #N/A?

MATCH returns the #N/A error when it cannot find the lookup value, and the cause depends on the match_type.

=MATCH(B2, A2:A5, 0)
With match_type 0, MATCH returns #N/A when B2 holds a value that is not in A2:A5. A typo, a trailing space, or a number stored as text all count as not found, even when the value looks right on screen.

With an exact match, #N/A means there is no matching entry, usually from a small mismatch: a typo, a stray space, or the number 1005 sitting next to the text 1005, which are not equal to MATCH. Clean the value and make both sides the same type. There is also an approximate-mode case: with match_type 1, a lookup value that falls below every entry in the ascending list returns #N/A, because there is nothing at or under it to settle for. What each error code means, and which ones are safe to ignore, is in Excel’s error values, explained.

The short version

Frequently asked questions

What does the MATCH function do in Excel?
MATCH returns the position of a value within a row or column, not the value itself. Its syntax is =MATCH(lookup_value, lookup_array, [match_type]), so =MATCH(40, B2:B5, 0) returns 3 when 40 is the third number in B2:B5. Because it hands back a position rather than a value, MATCH is most useful fed into another function such as INDEX.
What does the match_type argument do in MATCH?
It decides how MATCH matches. Set it to 0 for the first exact match, in a range in any order, which is what you want most of the time. Set it to 1 or leave it out and MATCH does an approximate match: it returns the largest value less than or equal to the one you asked for and assumes the range is sorted in ascending order. Set it to -1 for the smallest value greater than or equal to the lookup, with the range sorted descending. Because leaving it out gives the approximate behavior rather than an exact one, it is safest to write the 0.
What is the difference between MATCH and XMATCH?
XMATCH is the newer version, available in Excel for Microsoft 365 and Excel 2021 and later. Its syntax is =XMATCH(lookup_value, lookup_array, [match_mode], [search_mode]). The main difference is the default: XMATCH matches exactly unless you tell it otherwise, while MATCH defaults to an approximate match. XMATCH also adds a search_mode, so it can search from the bottom up to find the last match or run a binary search on sorted data.
Can MATCH find text with wildcards?
Yes, when match_type is 0 and the lookup value is text. A question mark stands for any single character and an asterisk stands for any run of characters, so a lookup for a value followed by an asterisk matches every entry that starts with it. To match a literal question mark or asterisk, put a tilde in front of it. XMATCH does the same with a match_mode of 2.
Why does my MATCH return #N/A?
MATCH returns the #N/A error when it cannot find the lookup value. With match_type 0 that means no exact match exists, usually from a typo, a trailing space, or a number stored as text that will not match a real number. With an approximate match_type it also happens when the lookup value falls below every entry in an ascending list, since there is nothing at or under it to settle for. Line up the value and the range so both sides are the same type, and check the sort order.
What is the difference between MATCH and INDEX MATCH?
MATCH on its own returns a position, a number. INDEX and MATCH is the combination that turns that position into a value: MATCH finds the row, and INDEX returns the cell sitting there. So use MATCH alone when you want the position itself, and the INDEX and MATCH pair when you want the value at that position.

Catch the errors before they ship

Reviewing a change to a model? Compare the two versions in your browser and see every changed cell, formula, and value. It's free, and nothing leaves your computer.