INDEX and MATCH Together
About this lesson
MATCH finds which row a value is in. INDEX returns the value in that row from any column. Together they look up in any direction.
- build a lookup from INDEX and MATCH that returns from any column, left or right.
- find a row by one column and read a value from another.
- find both the row and the column with two MATCHes.
The idea
It is more typing than VLOOKUP, and it is worth it for two reasons. It looks left: the column you search and the column you return are named separately. So the answer does not have to sit to the right of the question. And it survives an inserted column.
VLOOKUP's third argument is a count. 3 means "the third column of that range". Insert a new column in the middle and the 3 still says 3, but the data under it has moved one place. The formula does not break. It just returns the wrong column. INDEX and MATCH name their columns as ranges, and a range moves when a column is inserted before it. The formula that stays right when somebody else edits the sheet is the one to write.
The mistake to watch for
Ranges that start on different rows. MATCH counts from the top of the range it searched. INDEX reads from the top of the range it was given. So the two must begin on the same row, or every answer is the one above or below. Check both ranges before you check the data.
Where this comes up again
This lesson needs JavaScript to run. Everything below is the lesson in full, but you cannot type into the grid or be marked.
Build it in two halves. MATCH finds which row a name sits in.
In E2, type =MATCH(F2,B2:B5,0): F2 holds a name, B2:B5 the names, 0 exact.
| Row | A | B | C | D | E | F | G |
|---|---|---|---|---|---|---|---|
| 1 | Payroll no | Name | Department | Annual salary | |||
| 2 | 4102 | H. Okafor | Design | 41200 | T. Alvarez | ||
| 3 | 4118 | M. Lindqvist | Support | 33500 | |||
| 4 | 4126 | T. Alvarez | Design | 46800 | |||
| 5 | 4139 | P. Nwosu | Finance | 52400 | P. Nwosu | ||
| 6 | |||||||
| 7 | |||||||
| 8 |
Every step
-
Build it in two halves.
MATCHfinds which row a name sits in. InE2, type=MATCH(F2,B2:B5,0):F2holds a name,B2:B5the names, 0 exact. -
Now the other half.
INDEXfetches from a position. Read=INDEX(D2:D5,3)and say what it returns: the salaries, third one down. -
Put them together. In
E4, writeINDEXover the salariesD2:D5. Instead of a typed 3, use theMATCHfrom step 1 as the position. Then the salary follows the name inF2. -
Here is what
VLOOKUPcannot do at all.F5holds a name. InE5, get that person's payroll number. It sits to the left of the names. UseINDEXoverA2:A5, withMATCHsearchingB2:B5forF5. -
In
E6, write a formula withINDEXandMATCHthat gives the name of the person in the Finance department. Search the departments and return the names. -
INDEXcan take a row and a column, so aMATCHcan go in each. InE7, look in the whole tableA1:D5for M. Lindqvist's department. OneMATCHfinds the row by name inB1:B5. The other finds the column by the heading Department inA1:D1.