Knowledge base / Excel

MATCH in Excel: relative position, match modes and sorting

I explain why position 3 can mean worksheet row 4 and why omitting the last argument changes the lookup rule.

Kajo RudzińskiPublished Updated 6 min read

A magnifying glass selects one compartment in an ordered row.

I use MATCH when I need an item’s position within a list. I can then pass that position to INDEX to retrieve a value from a corresponding column. The last argument deserves particular attention: leaving out the match type enables approximate matching. For codes and identifiers, I therefore enter 0 explicitly before interpreting the returned position.

What MATCH returns

MATCH returns a relative position within the lookup range. Its first cell has position 1 even if it is located in worksheet row 10. The result is neither a cell address nor the associated value from another column. That distinction matters when functions are combined. Microsoft documents the syntax and result here.

The examples apply to contemporary versions listed in the documentation, including Microsoft 365 and Excel 2024, 2021, 2019 and 2016. I use English function names and commas between arguments. Your separator depends on regional settings; some installations require semicolons. The Polish function name is PODAJ.POZYCJĘ. Translating a function name without considering the application’s language and separators can leave an otherwise valid example unusable.

=MATCH(lookup_value,lookup_array,[match_type])

Square brackets mark an optional argument in the syntax description. They do not belong in an actual formula. In the small examples, I search one column and count positions from its top. This makes it easier to notice whether a header has accidentally entered the range or whether the starting cell moved during editing.

An exact match in a small table

Place these synthetic records in A1:B5, with headers in the first row and data beginning in row 2. Codes are numeric. The amounts simply demonstrate how the returned position can connect to INDEX; they do not describe real transactions.

Worksheet row A: code B: amount
2 10 100
3 20 200
4 30 300
5 40 400
=MATCH(30,A2:A5,0)

The result is 3. Reading 10, 20 and 30 from the beginning of the range, the requested code occupies the third position. Its worksheet row is 4. If A1:A5 is used accidentally, the header becomes part of the range and the position changes. Always identify where counting begins. Looking for 25 in A2:A5 with match type 0 finds no match and returns #N/A.

Exact mode does not require sorting. If a value occurs several times, it returns the first exact match. Finding a code therefore does not confirm that the code is unique. If one position must identify one product, duplicates need examination in the source. I do not silently treat the first record as a business rule for resolving conflicting amounts.

Approximate modes require the appropriate order

For the ascending list 10, 20, 30, 40, the following formula returns 2. The largest value no greater than 25 is 20, which occupies the second position. This searches for a threshold, rather than whichever number happens to be closest to 25.

=MATCH(25,A2:A5,1)

Match type 1 is the default, so omitting it does not request an exact match. Its lookup data must be ascending. Type -1 finds the smallest value no less than the lookup value and requires descending data. If D2:D5 contains 40, 30, 20, 10, looking for 25 returns position 2, corresponding to 30.

=MATCH(25,D2:D5,-1)

I do not describe an unsorted list as guaranteeing one particular error code. It may produce an incorrect position or an error. Microsoft discusses inconsistent match types and sorting here. Before interpreting an approximate result, inspect the ordering and the intended threshold rule. When looking up a specific identifier, return to an explicit 0 rather than relying on a plausible result from the default mode.

A selected position in an upper list connects to its corresponding position in a lower list.

Pass the position to INDEX

To retrieve the amount for code 30, I use corresponding ranges that start on the same row and describe the same records. MATCH returns 3. INDEX then reads the third element of B2:B5, giving 300.

=INDEX(B2:B5,MATCH(30,A2:A5,0))

INDEX selects an element by its location in a range. Shifting only one range can attach somebody else’s amount to the code. I trace one record from the lookup code to the returned amount before copying the formula. Relative and absolute references also deserve inspection: the lookup range should not move unintentionally for every new report row.

Text, duplicates and missing matches

MATCH does not distinguish uppercase from lowercase text. “Exact” describes the matching mode; it does not mean a case-sensitive comparison. In mode 0, text can also use wildcards: ? represents one character and * a sequence of characters. A tilde, ~, precedes a wildcard that should be treated literally. These behaviours are documented on the function’s reference page.

For an unexpected #N/A, I inspect whether the value exists, its data type and any extra characters. Numeric 30 and a text code “30” deserve attention after an import. I do not automatically attribute #VALUE! to the mere presence of different types in a list. First establish what was stored. Hiding every error behind an empty result would make missing matches harder to notice and could conceal an incomplete report.

Consider XMATCH when compatibility allows

XMATCH is available in Microsoft 365 and Excel 2024 and 2021, among other listed editions. Its default match is exact. In this example, =XMATCH(30,A2:A5) also returns position 3. Its arguments have their own definitions, so I do not transfer every match-type value from MATCH unchanged. Search modes need particular care when choosing a different search direction or algorithm.

In an existing workbook, I first check which Excel versions its readers use. Understanding MATCH remains useful for reading older files. A newer function does not eliminate duplicate codes or misaligned ranges. For the next step, read the INDEX entry and follow how a relative position becomes a returned amount.

Exercise: distinguish a position from a threshold

For A2:A5, explain the result of looking for 20 with mode 0 and 25 with mode 1. Move the complete table several rows down and update the references. Relative positions remain unchanged even though worksheet row numbers change. Finally, add another code 20 and explain why the first match cannot decide which amount is correct. This exercise checks the function’s meaning, rather than only the ability to copy its syntax.

Key takeaways

Does MATCH return a worksheet row number?

It returns a relative position within the lookup range. In A2:A5, position 3 is worksheet row 4.

What happens if I omit match_type?

The default is 1, an approximate threshold match requiring ascending data. Use an explicit 0 for a specific code.

Is an exact match case-sensitive?

No. MATCH does not distinguish uppercase and lowercase letters, including in mode 0.

AI was used in an automated way while working on this article. If you want to learn how to do it too, check out this project.

Kajo Rudziński

Newsletter KajoData

Let’s keep in touch.

I write about data analysis, learning and changing careers. My newsletter and the sign-up form are in Polish. If that works for you, I’d be glad to see you there.