Practice problems / Lookup & Reference

Look up a field that moves (VLOOKUP + MATCH)

Hard Lookup & Reference
Description
Hints 0/4
Solutions 2
–
Test case
1
2
3
Reset
Submit
fx
A
B
C
D
E
F
G
1
2
3
4
5
6
7
8
9
10
Loading interactive spreadsheet...
Preparing grid cells and formula calculation engine
○ Ready Enter formula in highlighted cells, then click Submit.

The problem

Problem statement

The monthly HR export keeps reordering its columns, so a hardcoded column number breaks on every refresh. The employee ID sits in E2 and the field you must return is chosen in G2 — Department today, Manager tomorrow. Fill the Result cell F2 so it returns whatever field G2 asks for.

Compute the column number with MATCH against the header row — hardcoding 3 answers case 1 and fails the moment G2 asks for Manager in case 2.

Problem data

Show the sheet as a table (selectable, copyable)
The exercise data, as a table
ABCDEFG
1 IDNameDepartmentManagerQuery IDResultField
2 E-201Ava ChenEngineeringDana ItoE-343Department
3 E-118Liam PatelMarketingAva Chen
4 E-343Sofia ReisFinanceDana Ito
5 E-227Noah KimDesignLiam Patel

Notes

VLOOKUP's third argument is a position, not a field name. MATCH($G$2, $A$1:$D$1, 0) converts the header text into that position, so the lookup follows the request. Keep the header range absolute: it must not shift when the formula is filled down.

How to approach

Your answer goes in F2. On submit we re-run your formula against 3 different sets of input, so a hardcoded number will fail — the formula has to follow the cells.

  1. Target cell is F2
  2. The employee ID is in E2; the field to return is named in G2
  3. MATCH(G2, A1:D1, 0) hands VLOOKUP the column number it wants
  4. Shape: =VLOOKUP(?, ?, MATCH(?, ?, 0), FALSE) — four arguments, the third one computed

Official solutions

Show 2 solutions — try it yourself first

Approach 1: VLOOKUP with a computed column index

=VLOOKUP($E$2,$A$1:$D$5,MATCH($G$2,$A$1:$D$1,0),FALSE)

MATCH finds Department or Manager in the header row and returns 3 or 4; VLOOKUP uses that number. Change G2 and the same formula returns a different field — no edit required.

Approach 2: INDEX with two MATCH calls

=INDEX($A$2:$D$5,MATCH($E$2,$A$2:$A$5,0),MATCH($G$2,$A$1:$D$1,0))

One MATCH finds the row (who), the other finds the column (which field). This version does not care that the lookup column is first, so it survives a reshaped export too.

Function guide

Related practice

FAQ

How do I make VLOOKUP return different columns without editing the formula?

Replace the column number with MATCH(header, header_row, 0). The requested field name then drives the position, so one formula answers 「show the department」 and 「show the manager」.

Why does a hardcoded column number break?

A column number is a position, not a meaning. When the export reorders columns, or when the requested field changes (case 2), position 3 is no longer the field you asked for.

What is a two-way lookup in Excel?

Row from one MATCH, column from another, and INDEX returns the intersection. It is the standard answer when both the row and the field are inputs rather than fixed.