Sub topic 10
MATCH: finding a key's position
This chapter covers MATCH, the function that returns where a key sits in a list instead of returning a value. It assumes you can enter formulas, use absolute and relative references ($A5, C$4), and have a flat data table with one row per record. The next chapter pairs MATCH with INDEX to build a full lookup.
What MATCH returns
MATCH searches a single row or column for a key and returns its position as a number. It does not return the value stored there. Position 1 is the first cell of the range you give it, not the first cell on the sheet.
The syntax is:
=MATCH(lookup_value, lookup_array, [match_type])lookup_valueis the key you are looking for, such as an account name or a header.lookup_arrayis one row or one column. A two-dimensional range returns#N/A.match_typeis 0, 1, or -1. If you leave it out, Excel uses 1. That default is a common source of silent errors.
Suppose the Assumptions sheet holds keys in B3:B12:
| Row | Column B (key) | Column C (value) |
|---|---|---|
| 3 | Tax rate | 0.25 |
| 4 | Inflation | 0.03 |
| 5 | Discount rate | 0.09 |
| 6 | Terminal growth | 0.02 |
This formula returns 3, because "Discount rate" is the third item in B3:B12, even though it sits on row 5 of the sheet:
=MATCH("Discount rate", Assumptions!$B$3:$B$12, 0)The position is relative to the range. If you later insert a row above row 3 and the range expands or shifts, the position can change. Positions are only meaningful together with the range that produced them.
Match types
The third argument controls how Excel compares keys.
| Match type | Behavior | Sort order required |
|---|---|---|
| 0 | Exact match only. Returns `#N/A` if the key is absent. | None |
| 1 | Largest value less than or equal to the key. | Ascending |
| -1 | Smallest value greater than or equal to the key. | Descending |
For exact keys such as account names, assumption labels, and column headers, always write 0. Writing MATCH($A5, range) with no third argument runs an approximate search. On unsorted text it can return a wrong position with no error, and the number still looks plausible. Chapter material on tiers covers match types 1 and -1 in detail. Here, treat 0 as the default you type every time.
Exact matching in practice
With match type 0, MATCH compares the key to each cell from the top and stops at the first hit. Three behaviors matter in a model.
- First match wins. If a key appears twice, MATCH returns the position of the first one and never reports the duplicate. A later row with a corrected value is ignored.
- Case is ignored. "tax rate" matches "Tax Rate".
- Wildcards work in text. With match type 0,
?matches one character and*matches any run of characters. This is useful for partial labels and a hazard if a key itself contains*or?.
=MATCH("Opex*", Data!$C$2:$C$5000, 0)This returns the position of the first category that starts with "Opex". It finds one position only, so it cannot total all matching rows. Totaling is the job of SUMIFS.
To search for a literal asterisk or question mark, put a tilde in front of it: "Margin~*" looks for the text Margin*.
Text, numbers, and hidden mismatches
MATCH is strict about type. The number 2025 and the text "2025" are different keys. This happens often when years or account codes are imported from another system as text. The visible cells look identical, and MATCH returns #N/A.
Trailing spaces cause the same failure. "Revenue " does not match "Revenue". When a lookup fails on a key that looks right, test the key directly:
=LEN($A5)
=ISNUMBER($A5)If LEN is longer than the visible text, there is a stray space. If ISNUMBER returns FALSE on a code you expected to be numeric, the cell holds text. Clean the source data once, in the data layer, instead of wrapping every lookup in TRIM or VALUE.
Finding a column position from a header
MATCH works on rows as well as columns. A row of month headers gives you a column position for the month you want:
=MATCH(C$4, Rates!$C$2:$H$2, 0)If C4 holds "Mar" and the header row is Jan through Jun, the result is 3. This is the building block for two-way lookups, where one MATCH finds the row and a second finds the column.
Using MATCH as a check
Because MATCH returns an error for a missing key, it can test whether a key exists. Wrapping it in ISNUMBER converts the result to TRUE or FALSE:
=ISNUMBER(MATCH($A5, Assumptions!$B$3:$B$12, 0))This tells you a key is present. It does not tell you the key is unique, because a duplicate still returns a position. To detect duplicates, count occurrences:
=COUNTIF(Assumptions!$B$3:$B$12, $A5)A result of 1 means exactly one match. A result of 0 means missing, and 2 or more means a duplicate that MATCH would hide. A model that relies on MATCH should carry this check beside it.
Worked example: locating an account block
A model has a Data sheet where each account's rows are grouped, and you want to know where the first "Rent" row sits so you can reference the block. In Data!B2:B5000:
=MATCH("Rent", Data!$B$2:$B$5000, 0)If the result is 14, the first Rent row is sheet row 15, because the range starts on row 2. Converting a position to a sheet row follows one rule: sheet row = position + first row of range - 1. Here, 14 + 2 - 1 = 15.
Mixing up position and sheet row is the most common beginner error with MATCH. It matters when you feed the result into functions that expect sheet rows, such as INDIRECT or OFFSET. INDEX expects a position within its own range, so it takes the MATCH output directly, provided both ranges start on the same row.
Keeping ranges aligned
When MATCH and a later INDEX use different starting rows, the result is shifted by the difference and returns the wrong value with no error. The rule is simple: the lookup range in MATCH and the return range in INDEX must start and end on the same rows.
=INDEX(Assumptions!$C$3:$C$12, MATCH($A5, Assumptions!$B$3:$B$12, 0))Both ranges run from row 3 to row 12. If one were $C$2:$C$12, every result would come from the row above the intended one.
Failure modes summary
| Symptom | Likely cause | Fix |
|---|---|---|
| `#N/A` on a key that looks present | Text versus number, or trailing space | Clean the source, check with `LEN` and `ISNUMBER` |
| Plausible but wrong position | Match type omitted or set to 1 on unsorted data | Write 0 explicitly |
| Correct position, wrong value from INDEX | Ranges start on different rows | Use identical row bounds |
| Newer duplicate row ignored | First match wins | Add a `COUNTIF` check |
| Position stops matching after inserted rows | Hard-coded numbers from earlier MATCH results | Keep MATCH live in the formula |
Exercise
The range Assumptions!$B$3:$B$12 holds the keys, and "Inflation" is on sheet row 4. (a) What does =MATCH("Inflation", Assumptions!$B$3:$B$12, 0) return? (b) A colleague writes =MATCH($A5, Assumptions!$B$3:$B$12) and gets a number that looks right on test data. Why is that formula risky? (c) What formula would you place beside it to catch a duplicate key?
Show answer
(a) It returns 2, because row 4 is the second cell of a range that starts on row 3. (b) With no third argument, Excel uses match type 1, which expects ascending sorted data. On unsorted keys it can return a wrong position with no error, so it may pass a test and fail later. It should be written with 0. (c) =COUNTIF(Assumptions!$B$3:$B$12, $A5), where any result other than 1 flags a missing or duplicated key.