Sub topic 1
What a Lookup Does
Prerequisites
This chapter assumes you can enter formulas in Google Sheets cells, read range references such as A2:C100, and use absolute references with $, such as $A$2:$C$100.
What a lookup does
A lookup takes a key, searches one column for that key, and returns a value from the same row in a different column. The key is the value you search for, such as an order ID. The lookup column is the column being searched. The result column holds the value you want back.
VLOOKUP: search key, range, and column index
VLOOKUP takes four arguments:
=VLOOKUP(search_key, range, column_index, is_sorted)The range must start with the lookup column. The column index counts columns from the left edge of the range, starting at 1. For example:
=VLOOKUP("P-102", A2:C100, 3, FALSE)This searches column A for "P-102" and returns the value in column C of the matching row.
Exact and approximate match: why the last argument matters
The fourth argument sets the match type. FALSE requests an exact match. TRUE, or an omitted argument, requests an approximate match. Approximate match assumes the lookup column is sorted in ascending order. It returns the largest value that is less than or equal to the key. This suits tier tables, such as commission rates by sales band:
=VLOOKUP(B2, $F$2:$G$6, 2, TRUE)For ID codes, always use FALSE. With the approximate default, a missing key can return a wrong row without any error.
Where VLOOKUP falls short
VLOOKUP has three main limits:
- It cannot look left. The result column must sit to the right of the lookup column.
- The column index is a fixed number. If you insert or delete a column in the range, a hard-coded
3points at the wrong column. - It returns
#N/Afor a missing key with exact match, and the approximate default can silently return a wrong row.
Exercise
In the range A2:D50, which column index returns the value in column C?
Show answer
3. Column A is index 1, column B is index 2, and column C is index 3.