Lookup Functions (VLOOKUP, XLOOKUP, INDEX, MATCH)
Lookup Functions: Find the Right Record
Lookup functions connect an identifier, such as a product code or customer ID, to information stored elsewhere in a worksheet. You use them to retrieve a price, supplier, or account manager without retyping it. The central task is to find the intended record and return the correct field. The formulas below use English function names and comma separators.
Start with the key and the return field
A lookup key is the value you search for in a reference list. A product code is usually a better key than a product description because descriptions may repeat. Choose keys that identify records uniquely when your task requires one unambiguous answer.
An exact match finds the specified key rather than substituting a nearby value. Use exact matching for identifiers: a neighbouring account number belongs to a different account. These standard lookup methods do not distinguish uppercase from lowercase text.
The search and return ranges must represent the same records in the same order. A correct match can still return the wrong information if the return range starts one row too early.
Retrieve a value with VLOOKUP or XLOOKUP
Suppose A2:A20 contains product codes, B2:B20 contains names, C2:C20 contains prices in CAD per item, and F2 contains the requested code.
=VLOOKUP(F2,A2:C20,3,FALSE)
VLOOKUP searches the first column of A2:C20. Its third argument, 3, selects the third column of that table, so the result comes from column C. FALSE requests an exact match. With a standard table range, VLOOKUP returns fields in the key column or to its right.
=XLOOKUP(F2,A2:A20,C2:C20,"Check code",0)
XLOOKUP names the search and return ranges separately. The fourth argument supplies a message when the key is absent; the fifth argument, 0, explicitly requests exact matching, which is also its default. The return range can be on either side of the search range. XLOOKUP is available in Microsoft 365 and Excel 2021 or later, but not Excel 2016 or 2019.
Approximate VLOOKUP is useful for a table of minimum thresholds, such as discount bands. With the first column sorted ascending, TRUE returns the row with the largest threshold less than or equal to the input. An input below the smallest threshold returns #N/A. This is a deliberate band selection, not an interchangeable substitute for an exact ID lookup.
Separate the position from the value
=MATCH(F2,A2:A20,0)
MATCH returns the key's position within A2:A20. Its final 0 requests an exact match. Position 1 means A2, not worksheet row 1. Omitting that argument selects an approximate mode that expects ascending data.
=INDEX(C2:C20,MATCH(F2,A2:A20,0))
INDEX retrieves the value at the position supplied by MATCH. Here, the matched position in the code range selects the corresponding price. INDEX and MATCH can also retrieve a field to the left of its key.
Approach | Search arrangement | Result |
|---|---|---|
VLOOKUP | Keys in the table's first column | Value from a numbered table column |
XLOOKUP | Separate search and return ranges | Corresponding value from the return range |
MATCH | One search range | Relative position of a match |
INDEX | A range and a supplied position | Value at that position |
Check which record you retrieved
Exact VLOOKUP, MATCH with 0, and default XLOOKUP select the first matching record. Duplicate keys therefore require a rule. XLOOKUP's sixth argument, -1, searches from last to first. This selects the latest entry only when record order makes the last match the latest.
For a missing exact key, VLOOKUP and MATCH return #N/A; XLOOKUP does too unless you provide an alternative. Check missing keys, inconsistent number-versus-text storage, extra spaces, and range alignment before accepting a result.
What to remember
- Choose the key, return field, and matching rule before writing the formula.
- Use FALSE for exact VLOOKUP and 0 for exact MATCH.
- MATCH supplies a position; INDEX retrieves the value.
- Verify range alignment, missing keys, and duplicate-key rules.
Example: Retrieve details for a supply order
You prepare a supply order using the catalogue in A1:C5 below. Product codes are unique text identifiers, and each price is in CAD per pack. Cell F2 contains K-563. The workbook supports XLOOKUP and uses English function names with comma separators.
Worksheet row | A: Product code | B: Supplier | C: Price, CAD per pack |
|---|---|---|---|
2 | K-417 | Harbour | 14.80 |
3 | K-208 | Summit | 8.60 |
4 | K-563 | Canal | 23.40 |
5 | K-349 | Cedar | 11.25 |
Use exact matching throughout. Keep the catalogue in its current order.
a) Write a VLOOKUP formula that retrieves the price for the product in F2. State its result with units.
The lookup key is in F2. Select A2:C5 because its first column contains the product codes and its third column contains the prices.
- Use F2 as the lookup value.
- Use A2:C5 as the table, excluding the header row.
- Count A as column 1, B as column 2, and C as column ________.
- Set the final argument to FALSE for an exact code match.
=VLOOKUP(F2,A2:C5,3,FALSE)
The matching code K-563 is in ________. The formula retrieves C4, giving 23.40 CAD per pack. Exact matching does not require these codes to be sorted.
b) Write an XLOOKUP formula that retrieves the supplier for the product in F2. Include the message Check code if no exact match exists.
XLOOKUP uses separate search and return ranges. Search for the code in A2:A5 and return the supplier from the corresponding position in B2:B5.
- Set the lookup value to F2.
- Set the search range to A2:A5.
- Set the return range to B2:B5.
- Supply "Check code" as the missing-key message.
- Supply 0 as the exact-match mode.
=XLOOKUP(F2,A2:A5,B2:B5,"Check code",0)
K-563 occupies the ________ position in A2:A5. The third position in B2:B5 is ________, so the result is Canal. The message is not used because the requested code exists.
c) Retrieve the price using INDEX and MATCH. Show the intermediate MATCH result and explain how it identifies the returned cell.
First, find the exact code's position within the code range:
=MATCH(F2,A2:A5,0)
A2 is position 1, A3 is position 2, and A4 is position 3. Since A4 contains K-563, MATCH returns 3. This is a position within the range, even though the matching cell is on worksheet row 4.
Next, supply that position to INDEX using the aligned price range:
=INDEX(C2:C5,MATCH(F2,A2:A5,0))
For this input, the formula is equivalent to:
=INDEX(C2:C5,3)
The third cell of C2:C5 is C4. Its value is 23.40 CAD per pack, agreeing with the VLOOKUP result. Both ranges begin on row 2, so equal positions identify the same catalogue record.
A purchasing assistant uses XLOOKUP to retrieve supplier names from product identifiers. Match each function argument to its purpose when constructing the lookup formula.
The product identifier supplied as the search target
The cells containing the product identifiers to search
The setting that chooses exact, next-smaller, next-larger or wildcard matching
The message to display when no acceptable match exists
The cells containing the supplier names to retrieve
lookup_array
if_not_found
match_mode
return_array
lookup_value
A service desk stores numeric client IDs in A6:A9 as shown. Cell F2 contains the number 7359. What does =MATCH(F2,A6:A9,0) return?
Worksheet row | A: Client ID |
|---|---|
6 | 6107 |
7 | 6824 |
8 | 7359 |
9 | 7941 |