INDEX MATCH Generator
Fill in the return column, the value to find and the search column, then copy a working INDEX and MATCH formula with an explanation underneath.
Updated
MATCH finds the position of E2 in A2:A6; INDEX returns the value at that position in C2:C6.
Paste the formula into cell F2 or any empty cell. The coloured parts match the coloured fields. Using a different list separator? Replace the commas with semicolons.
How to use the generator
- Column to return. Enter the range that holds the answer you want, such as the prices in
C2:C6. - Value to look up. Enter the cell that holds what you are searching for, such as a product code in
E2. - Column to search. Enter the range that contains the lookup values. It must cover the same rows as the return column.
- If nothing is found, show. Optional. Enter text to display in place of #N/A.
- Select Copy and paste the formula into your sheet.
With the starting values the generator writes:
=INDEX(C2:C6, MATCH(E2, A2:A6, 0))
The fields are in the order the formula uses them, which is why the return column comes first.
How the two functions work together
Each function does half of the job.
=MATCH(lookup_value, lookup_array, [match_type])
=INDEX(array, row_num, [column_num])
MATCH searches a range and returns a position. If E2 holds a code that sits in the third cell of A2:A6, MATCH(E2, A2:A6, 0) returns 3.
INDEX returns the value at a position in a range. INDEX(C2:C6, 3) returns the third cell of C2:C6, which is C4.
Put MATCH inside INDEX and the position found in one column is used to read from another:
| Part | Meaning |
|---|---|
C2:C6 |
The column to return a value from. |
E2 |
The value to find. |
A2:A6 |
The column to search. |
0 |
Exact match. |
The position is counted from the top of the range, so both ranges must start on the same row and have the same height.
MATCH’s third argument
| Value | Behaviour |
|---|---|
0 |
Exact match. The data can be in any order. |
1 |
The largest value that is less than or equal to the lookup value. The column must be sorted ascending. This is the default when the argument is left out. |
-1 |
The smallest value that is greater than or equal to the lookup value. The column must be sorted descending. |
The generator always writes 0. Leaving the argument out is the most common fault in hand-typed formulas, because the default of 1 returns a plausible wrong answer on unsorted data.
Why people use INDEX and MATCH
- It looks left. The return column can be anywhere, including to the left of the search column. To find a name in column C and return the ID from column A, use
=INDEX(A2:A6, MATCH(E2, C2:C6, 0)). VLOOKUP cannot do this. - It survives inserted columns. VLOOKUP stores the return column as a number, such as 3. Insert a column in the table and 3 now points at the wrong one. INDEX and MATCH hold two real ranges, and Excel moves them with the data.
- It works in every version. XLOOKUP offers the same benefits and needs Excel 2021 or Microsoft 365. INDEX and MATCH open correctly in any version.
- It reads only two columns. The formula refers to the search column and the return column, and ignores what lies between them.
Two-way lookup
A second MATCH can pick the column as well as the row. With row labels in A2:A10, column headings in B1:E1 and the numbers in B2:E10:
=INDEX(B2:E10, MATCH(G1, A2:A10, 0), MATCH(G2, B1:E1, 0))
The first MATCH finds the label in G1 down the side and gives the row number. The second finds the heading in G2 across the top and gives the column number. INDEX returns the cell where they cross. This suits price grids, rate tables and monthly reports, where you pick a product in one cell and a month in another.
Build the one-way formula in the generator first, then widen the INDEX range and add the second MATCH by hand.
Copying the formula down a column
When you fill the formula down, both ranges shift by one row each time unless you lock them. Lock the ranges and leave the lookup value free:
=INDEX($C$2:$C$6, MATCH(E2, $A$2:$A$6, 0))
Press F4 while the cursor is on a range to add the dollar signs.
Showing something other than #N/A
Fill in If nothing is found, show and the generator wraps the formula in IFERROR:
=IFERROR(INDEX(C2:C6, MATCH(E2, A2:A6, 0)), "Not found")
IFERROR hides every error, including a mistyped range, so add it once the formula is working. See the IFERROR page for details.
Common mistakes
- Ranges that do not line up. If the return range is
C2:C6and the search range isA1:A5, every result is one row off. Start both on the same row. - Ranges of different heights. A match beyond the end of the shorter return range gives #REF!.
- Leaving out the 0. MATCH then assumes sorted data. Keep the 0 unless you are looking up a number in sorted bands.
- Swapping the two ranges. The return column goes in INDEX. The search column goes in MATCH.
- Numbers stored as text. The text “1001” does not match the number 1001. Make both sides the same type.
For a full reference with a worked example, see the INDEX and MATCH page, or pick another function in the Excel formula generator.
Questions
How do I write an INDEX MATCH formula?
Put the column you want returned in INDEX, and let MATCH find the row: =INDEX(C2:C6, MATCH(E2, A2:A6, 0)). MATCH looks for E2 in A2:A6 and INDEX returns the value at that position in C2:C6.
Why use INDEX MATCH instead of VLOOKUP?
It can return a column to the left of the search column, it keeps working when columns are inserted or deleted, and it does not need a column number. VLOOKUP is shorter to type when the search column is the first column of the table.
What does the 0 in MATCH mean?
It asks for an exact match. Without it MATCH uses 1, which assumes the search column is sorted in ascending order and can return the wrong row with no warning. Always include the 0 for codes, names and IDs.
Does INDEX MATCH work in all versions of Excel?
Yes. Both functions are in every version of Excel, in Google Sheets and in LibreOffice Calc, so the formula is safe in files that many people open.
How do I do a two-way lookup with INDEX and MATCH?
Use one MATCH for the row and a second for the column: =INDEX(B2:E10, MATCH(G1, A2:A10, 0), MATCH(G2, B1:E1, 0)). The first finds G1 in the row labels and the second finds G2 in the column headings.
Why does my INDEX MATCH return #N/A?
MATCH did not find the value. Check for extra spaces, numbers stored as text, and a search range that shifted when the formula was filled down. A #REF! error means the two ranges are different sizes.