Knowledge base / Excel

INDEX in Excel: relative positions and MATCH lookups

One small table explains selecting a position, aligning lookup ranges and distinguishing a value from a cell reference.

Kajo RudzińskiPublished Updated 5 min read

A highlighted cube sits where a glowing row and column intersect in a grid.

INDEX selects a value or reference by its position within a range. I begin with that distinction because the function does not itself search for a product name. If I know the position, I can retrieve the item. If I know the name, I also need a way to find its position. The small table below is synthetic. I derive results from the documentation and visible cells, without claiming to have executed Excel.

Syntax and relative positions

Microsoft documents INDEX for Microsoft 365 and versions including Excel 2016, 2019, 2021 and 2024. The array form is:

=INDEX(array,row_num,[column_num])

Square brackets mark an optional argument in the syntax description; do not type them into a formula. English examples use English names and commas between arguments. Polish examples use local names, semicolons and decimal commas. Actual separators depend on Excel and system settings, so check the convention in your workbook.

Place the data in A1:B4, with headers in row 1:

Worksheet row A: Product B: Price
1 Product Price
2 Apples 3.50
3 Bananas 4.20
4 Oranges 5.00

The worksheet-row column only describes locations; it is not an extra column to paste into A. =INDEX(B2:B4,2) selects the second item of that range, B3, containing 4.20. =INDEX(A2:B4,3,2) selects its third row and second column, B4, containing 5.00. Positions are relative to the start of the supplied range rather than the entire worksheet.

Find a position, then retrieve a price

For an exact name match, I use MATCH with match type 0. Its returned position becomes the INDEX row argument:

=INDEX(B2:B4,MATCH("Bananas",A2:A4,0))

Bananas is at position 2 in A2:A4. The second item in B2:B4 is 4.20. Both ranges start on the same row and describe corresponding records. Shifting the name range down a row can return an existing but incorrect price. A formula without an error message still needs a check against a known example; syntactic success does not prove the ranges are aligned.

An exact match returns the first matching position. If names are not unique, decide whether that rule is appropriate. A product code may be a better key for multiple variants. I do not choose the first price accidentally. If the name is absent, MATCH returns #N/A and the combined formula propagates it. Microsoft advises investigating the cause before hiding it with error handling.

A lens locates an item in the left tray, and a bridge points to the aligned item in the right tray.

A reference is not an address string

Microsoft also documents the reference form:

=INDEX(reference,row_num,[column_num],[area_num])

It can choose an area among nonadjacent ranges on the same worksheet. The default area number is 1. The result is a reference that another formula can use as part of a range, rather than an address string such as “B3”. Depending on the surrounding formula, the selected location can be used as a reference or its value.

For example, =SUM(B2:INDEX(B2:B4,2)) uses INDEX to set the endpoint of B2:B3. The sum is 7.70, from 3.50 and 4.20. No text addresses are concatenated. Zero in the appropriate position argument can select a whole row or column. Receiving an array result depends on the version: current Microsoft 365 can spill it dynamically, while older array formulas need their appropriate entry method. The basic exercise here retains a single-cell result.

A count does not locate the last value

The older English entry presented =INDEX(A:A,COUNTA(A:A)) as a general last-value formula. COUNTA counts nonempty cells, including formulas returning empty text. That count need not equal the last occupied position. With entries only in A1 and A3, it returns 2, so INDEX selects A2 even though the last entry is below it.

I first define “last”: the last occupied row, last number or latest date. Those are different questions when a table has gaps. I do not replace a flawed shortcut with a complicated formula before defining the need. For a known position, I use a bounded range. For new lookup work, consider XLOOKUP, remembering that Excel 2016 and 2019 do not support it.

Errors and an independent exercise

An out-of-range position gives #REF! (#ADR! in Polish). An absent exact-match name gives #N/A (#N/D). Before replacing an error with zero, inspect the position, both range boundaries and the key’s data type. Zero might be a valid price, so it is not a universal missing-data message. I also make no blanket claim that INDEX with MATCH is faster than VLOOKUP; that would require measurement of the actual workbook.

On paper, move the whole table down two rows and write the new ranges. Bananas remains at relative position 2 within the data. Add a second product with the same name and explain which price the lookup chooses. Distinguishing a position, a key and a reference gives you a basis for building intentional lookups. Continue with the MATCH entry for the next step.

Key takeaways

Does INDEX search for a product name itself?

No. It selects by position. MATCH can find the name position, using match type 0 for an exact match.

Is row_num the worksheet row number?

No. It is relative to the start of the supplied range. The second row of B2:B4 is cell B3.

Does COUNTA always identify the last position?

No. It counts nonempty cells rather than locating the last one. Gaps and additional content can invalidate that shortcut.

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.