Easier to read with cream paper, a tint, more contrast or larger text? Choose your colours and text, once, for every page.

Preview

AC 2.3: Looking values up with VLOOKUP and HLOOKUP

This is the first page of the lesson. Read it and have a go at the activities. The rest is in the full lesson.

60 minutes

Typing the price again and again

A shop till list holds only item codes. The price is on a separate price list. Typing every price by hand for 300 orders would take all day and bring in mistakes.

A lookup finds the price for you, using the code.

Key words

WordWhat it means
Lookupfinding a value in one table by searching for a key in another place
VLOOKUPsearches down the first column and reads across from the row it finds
HLOOKUPsearches along the first row and reads down from the column it finds
Exact matchthe search value has to be identical to the one found
Error valuea message such as #N/A that a formula shows when it fails
IFERRORshows a fallback of your choice when a formula gives an error
Formulaa calculation typed into a cell, starting with =

The cells students fill in are left blank in this preview.

By the end of this lesson

Note

I can use VLOOKUP, HLOOKUP and IFERROR to find values, and say when each is used.

Starter

Have a go

Starter

3 questions
Have a go: your answers are marked here and then forgotten. Sign in if you would like your score kept, and to pick up where you left off.Sign in to keep your score

Your answers are marked here and are not kept. A college account keeps every student’s marks.

No spreadsheet here

Important

This platform has no spreadsheet program. Here the cells are a table and the formula is shown as text. You do the same job with code. On site you use a real spreadsheet program.

The price list as cells

RowA codeB itemC price in pence
1C1Cola120
2A1Apple40
3K1Cookie110
4W1Water80

The cells students fill in are left blank in this preview.

VLOOKUP, part by part

PartIn `=VLOOKUP("K1", A1:C4, 3, FALSE)`Meaning
Search value`"K1"`What to look for
Table`A1:C4`Search the first column of this block
Column number`3`Read the third column of the row found
Match type`FALSE`Exact match only
Answer110The price of K1

The cells students fill in are left blank in this preview.

Try it: the same lookup in Python

Code: python
prices = [["C1", "Cola", 120], ["A1", "Apple", 40], ["K1", "Cookie", 110]]
wanted = "K1"
answer = "#N/A"
for row in prices:
    if row[0] == wanted:
        answer = row[2]
print(answer)

# Change wanted to "Z9". What is printed?

HLOOKUP turns it on its side

Use HLOOKUP when the headings run along the top, not down the side. It searches the first row and reads down.

=HLOOKUP("K1", A1:C3, 3, FALSE) on a sideways list gives 110 too. Choose V for a list that runs down and H for a list that runs across.

The lesson goes on

7 more parts of this lesson are in the full curriculum, with the tasks, the final check and the labs. A college account gives your students all of it.