Excel Supreme

Excel track · Exercise 43 of 86 Paid

INDEX + MATCH: lookup either way

Return a value from any column, whichever side of the key it sits on.

Advanced

Employee directory

Read-only data · answer in E3

In E3, return the salary for the ID in D3 with INDEX and MATCH instead of VLOOKUP.

ABCDE
1IDNameSalaryLookupResult
2E-101Ana61500
3E-102Bo57000E-103
4E-103Cy88000
5E-104Dee54000
6E-105Eli49500

Download this grid (.xlsx) Two tabs: the grid you see, and the answer.

E3

What it does

MATCH counts where a value sits inside the range you give it. E-103 sits in D3, and A2:A6 starts at E-101, so the ID lands on 3: the third cell down, which is sheet row 4. Ask MATCH on its own and 3 is all you get.

INDEX turns that count into the contents of a cell. Give it C2:C6 and the number 3, and it reads C4, where Cy's salary of 88000 sits. The answer goes in E3. The two calls are separate, so you can test the 3 before wrapping INDEX around it.

The zero in MATCH decides how it searches. Without it MATCH assumes a sorted list, so a missing ID can return a neighbouring row and the salary of the wrong person. With the zero it returns #N/A. Because each range is chosen separately, the salary column can sit left of the ID, which VLOOKUP cannot manage.

Syntax

=INDEX(return_column, MATCH(lookup_value, search_column, 0))

Worked example

On Employee directory, =INDEX(C2:C6,MATCH(D3,A2:A6,0)) returns 88000.

=INDEX(C2:C6,MATCH(D3,A2:A6,0))

Common errors

Error codes for INDEX and MATCH
ErrorWhat it means and how to fix it
#N/AMATCH found no exact E-103 in A2:A6, usually because the ID carries a trailing space or is stored as text.
#REF!The row number from MATCH sits past the end of C2:C6, which happens when the two ranges cover different numbers of rows.
#VALUE!INDEX was handed no row number, or MATCH was given the whole table where a single column belongs.

At work

Payroll and staff directories, where the column you need is chosen after the column you search.