Courses Learn Blog Contact
Get Started →
Lesson 16

Week 4, Live 1: VLOOKUP, XLOOKUP, INDEX and MATCH, and Lookup Errors

Pulling a value from another table: why VLOOKUP breaks, how XLOOKUP fixes it, and IFERROR for the misses.

Webbo3 Data Analytics Cohort 2: Excel Track 18 min read Free

Webbo3 Data Analytics · Cohort 2 · Excel Track · Week 4, Live 1

VLOOKUP, XLOOKUP, INDEX and MATCH, and Lookup Errors

The workbook has three tabs of data, and they share codes. Today you pull a value from one tab into another, see exactly how the old way breaks, and use the new way that does not.

By the end of this class you can

  • Explain what a lookup does, using a phone's contact list
  • Pull a brand from the Product Catalogue with VLOOKUP, and say what each argument means
  • Show two ways VLOOKUP breaks: an inserted column, and a value to the left
  • Use XLOOKUP as the fix, including its built-in "not found" message
  • Use INDEX and MATCH on older versions of Excel
  • Handle #N/A with IFERROR, without hiding dirty data

Every sale in Sales Data carries a Product_ID, such as PRD-015. The Product Catalogue tab has one row per product ID: its name, category, brand, price, VAT and warranty. Nothing is copied between the two. A lookup is how one tab reads the other.

What we are looking atWe want to see the Product Catalogue tab: one row for each of the twenty products.
XTechPlug_Sales_Workbook.xlsx - Excel
The Product Catalogue tab
ABCDEFG
1Product_IDProduct_NameCategoryBrandUnit_PriceVAT_InclusiveWarranty_Months
2PRD-001Samsung Galaxy A54SmartphonesSamsung189,000Yes12
3PRD-002Tecno Spark 20SmartphonesTecno89,000Yes12
4PRD-003iPhone 14SmartphonesApple699,000Yes12
5PRD-004Infinix Hot 40SmartphonesInfinix75,000Yes12
6PRD-005HP Laptop 15LaptopsHP450,000Yes24
7PRD-006Lenovo IdeaPad 3LaptopsLenovo380,000Yes24
8PRD-007Dell Inspiron 15LaptopsDell520,000Yes24
9PRD-008Acer Aspire 5LaptopsAcer410,000Yes24
10PRD-009Samsung 43" TVTelevisionsSamsung250,000Yes12
11PRD-010LG 32" TVTelevisionsLG180,000Yes12
12PRD-011Hisense 50" TVTelevisionsHisense310,000Yes12
13PRD-012Sony 55" TVTelevisionsSony420,000Yes12
14PRD-013Scanfrost Fridge 200LAppliancesScanfrost195,000Yes24
15PRD-014LG Washing MachineAppliancesLG285,000Yes24
16PRD-015Thermocool AC 1.5HPAppliancesThermocool380,000Yes24
17PRD-016Sumec Generator 3.5KVAAppliancesSumec220,000Yes24
18PRD-017JBL Bluetooth SpeakerAccessoriesJBL45,000Yes6
19PRD-018Anker Power Bank 20KAccessoriesAnker28,000Yes6
20PRD-019TP-Link WiFi RouterAccessoriesTP-Link35,000Yes6
21PRD-020Logitech Wireless MouseAccessoriesLogitech18,000Yes6
Cleaning ProcessSales DataProduct CatalogueStaff Directory

1. What a Lookup Is

Definition

A lookup finds a value in one column of a table and returns the value from another column on the same row. You give it something you know (a product ID) and it hands back something you need (that product's brand).

Real-Life Scenario

Your phone's contacts. You type "Mama" (what you know) and it shows her number (what you need). You do not scroll and read; the phone finds the row and hands back the other column. If you type "Mamma", it finds nothing: a lookup needs an exact match.

Why Not Just Type the Brand Into Sales Data?

Because the catalogue is maintained in one place. When a price changes, it changes once, on the Product Catalogue tab, and every lookup picks it up. Typing details into a thousand rows is how a business ends up selling at last year's price, and how names end up spelt ten different ways, as you saw in Week 2.

Three Ways to Look Something Up

FunctionAvailable inIn one line
VLOOKUPEvery versionLook in the first column of a table, return the column you count to
XLOOKUPExcel 2021, Microsoft 365, Excel for the webLook in one column, return another, by pointing at it
INDEX + MATCHEvery versionMATCH finds the row number; INDEX returns the value at that row

2. VLOOKUP

Definition

VLOOKUP(lookup_value, table_array, col_index_num, range_lookup). Look for lookup_value in the first column of table_array, go across to column number col_index_num of that table, and return what is there. The V is for vertical: it searches down a column.

ArgumentFor a product's brandMeaning
lookup_valueC2The Product_ID on this sale
table_array'Product Catalogue'!$A$2:$G$21The whole catalogue, locked with $ so it does not move when filled. The tab name is in single quotes because it has a space in it
col_index_num4Return the 4th column of the table: Brand
range_lookupFALSEExact match only. Always FALSE in this track

Brand goes in column P, the first empty column after Zone.

What this formula doesWe want each sale's brand fetched from the Product Catalogue by its Product_ID.
XTechPlug_Sales_Workbook.xlsx - Excel
After Enter and Fill Down
P2
fx
=VLOOKUP(C2,'Product Catalogue'!$A$2:$G$21,4,FALSE)
A⋯CD⋯P
1Transaction_IDProduct_IDProduct_NameBrand
2TP-0892PRD-015Thermocool AC 1.5HPThermocool
3TP-0785PRD-004Infinix Hot 40Infinix
4TP-0210PRD-018Anker Power Bank 20KAnker
5TP-0343PRD-009Samsung 43" TVSamsung
6TP-0238PRD-020Logitech Wireless MouseLogitech
⋮⋮⋮⋮⋮
22TP-0511PRD-014LG Washing MachineLG
⋮⋮⋮⋮⋮
27TP-0454PRD-014LG Washing MachineLG
Filled down from P2 to P1051: 1,050 rows. Rows 2, 3, 4, 5, 6, 22, 27 shown.
Cleaning ProcessSales DataProduct CatalogueStaff Directory

Every sale now has its real brand, all 1,050 of them. Look for an iPhone 14 sale: its brand says Apple. In Week 2, cutting the first word off the product name could only ever say "iPhone". A lookup reads what is true; cutting text reads what happens to be written.

Always Write FALSE

Leave the last argument out and VLOOKUP does an approximate match, which assumes the first column is sorted and can quietly return a different product's details. FALSE means "exact match or nothing".

How VLOOKUP Breaks, 1: Someone Inserts a Column

Procurement adds a Supplier column to the Product Catalogue, between Category and Brand. Excel stretches your table_array to include it, but the 4 in your formula is just a number. It still says "the fourth column", and the fourth column is now Supplier.

What this formula doesWe want to see what the same VLOOKUP returns after a Supplier column is inserted into the catalogue.
XTechPlug_Sales_Workbook.xlsx - Excel
After Enter and Fill Down
P2
fx
=VLOOKUP(C2,'Product Catalogue'!$A$2:$H$21,4,FALSE)
A⋯CD⋯P
1Transaction_IDProduct_IDProduct_NameBrand
2TP-0892PRD-015Thermocool AC 1.5HPApapa Home Supplies
3TP-0785PRD-004Infinix Hot 40Ikeja Phone Imports
4TP-0210PRD-018Anker Power Bank 20KComputer Village Supplies
5TP-0343PRD-009Samsung 43" TVAlaba Electronics Hub
6TP-0238PRD-020Logitech Wireless MouseComputer Village Supplies
⋮⋮⋮⋮⋮
22TP-0511PRD-014LG Washing MachineApapa Home Supplies
⋮⋮⋮⋮⋮
27TP-0454PRD-014LG Washing MachineApapa Home Supplies
Filled down from P2 to P1051: 1,050 rows. Rows 2, 3, 4, 5, 6, 22, 27 shown.
Cleaning ProcessSales DataProduct CatalogueStaff Directory

No error. No warning. Every brand has become a supplier's name. If this column fed a report by brand, the report would now be about suppliers, and nobody would notice until a manager asked why Apple had vanished.

How VLOOKUP Breaks, 2: The Answer Is to the Left

A manager asks: "what is the Product_ID of the Dell Inspiron 15?" Now you know the name and need the ID. But VLOOKUP only searches the first column of its table and only returns columns to its right. Product_Name is column B, Product_ID column A. VLOOKUP cannot do it without rearranging the catalogue.

Picture This

Picture giving someone directions by counting: "the fourth door on the left". It works until someone builds a new door in the corridor. Then they walk confidently into the wrong room.

3. XLOOKUP: The Fix

Definition

XLOOKUP(lookup_value, lookup_array, return_array, if_not_found). Look for lookup_value in lookup_array and return the matching value from return_array. You point at the column to return instead of counting to it. It does an exact match unless you ask for anything else.

Real-Life Scenario

Directions by name instead of by counting: "the door marked Accounts". Build as many new doors as you like; Accounts is still Accounts.

What this formula doesWe want each sale's brand fetched with XLOOKUP: look up the Product_ID in the catalogue's ID column and return its Brand column.
XTechPlug_Sales_Workbook.xlsx - Excel
After Enter and Fill Down
P2
fx
=XLOOKUP(C2,'Product Catalogue'!$A$2:$A$21,'Product Catalogue'!$D$2:$D$21)
A⋯CD⋯P
1Transaction_IDProduct_IDProduct_NameBrand
2TP-0892PRD-015Thermocool AC 1.5HPThermocool
3TP-0785PRD-004Infinix Hot 40Infinix
4TP-0210PRD-018Anker Power Bank 20KAnker
5TP-0343PRD-009Samsung 43" TVSamsung
6TP-0238PRD-020Logitech Wireless MouseLogitech
⋮⋮⋮⋮⋮
22TP-0511PRD-014LG Washing MachineLG
⋮⋮⋮⋮⋮
27TP-0454PRD-014LG Washing MachineLG
Filled down from P2 to P1051: 1,050 rows. Rows 2, 3, 4, 5, 6, 22, 27 shown.
Cleaning ProcessSales DataProduct CatalogueStaff Directory

The same brands. Now insert the same Supplier column. Excel moves the return range along with the Brand column, from D to E, because it points at the column itself:

What this formula doesWe want to see XLOOKUP after the Supplier column is inserted: the return range has moved with the Brand column.
XTechPlug_Sales_Workbook.xlsx - Excel
After Enter and Fill Down
P2
fx
=XLOOKUP(C2,'Product Catalogue'!$A$2:$A$21,'Product Catalogue'!$E$2:$E$21)
A⋯CD⋯P
1Transaction_IDProduct_IDProduct_NameBrand
2TP-0892PRD-015Thermocool AC 1.5HPThermocool
3TP-0785PRD-004Infinix Hot 40Infinix
4TP-0210PRD-018Anker Power Bank 20KAnker
5TP-0343PRD-009Samsung 43" TVSamsung
6TP-0238PRD-020Logitech Wireless MouseLogitech
⋮⋮⋮⋮⋮
22TP-0511PRD-014LG Washing MachineLG
⋮⋮⋮⋮⋮
27TP-0454PRD-014LG Washing MachineLG
Filled down from P2 to P1051: 1,050 rows. Rows 2, 3, 4, 5, 6, 22, 27 shown.
Cleaning ProcessSales DataProduct CatalogueStaff Directory

Still brands. You did not touch the formula: Excel updated $D to $E for you when the column was inserted, because the reference pointed at the Brand column, not at "column 4".

Looking to the Left

What these formulas doWe want the Product_ID of the Dell Inspiron 15: look up the name, return the ID to its left.
XTechPlug_Sales_Workbook.xlsx - Excel
After Enter
R2
fx
=XLOOKUP("Dell Inspiron 15",'Product Catalogue'!$B$2:$B$21,'Product Catalogue'!$A$2:$A$21)
QR
1QuestionAnswer
2ID of the Dell Inspiron 15PRD-007
Cleaning ProcessSales DataProduct CatalogueStaff Directory
What is typed in each cell
R2 =XLOOKUP("Dell Inspiron 15",'Product Catalogue'!$B$2:$B$21,'Product Catalogue'!$A$2:$A$21)

PRD-007. XLOOKUP does not care which side the answer is on.

VLOOKUPXLOOKUP
How you choose the resultA column number you countThe column itself
A column inserted in the tableReturns the wrong column, silentlyKeeps working
Result to the leftImpossibleFine
Exact matchOnly if you remember FALSEBy default
Not found#N/A#N/A, or your own message as the 4th argument
Picture This

Picture the door marked Accounts. New doors appear, the corridor is repainted, but you walk straight to the right room every time because you were never counting.

4. INDEX and MATCH, for Older Excel

Definition

Two functions working as a pair. MATCH(lookup_value, lookup_array, 0) returns the position of the value in the list (the 0 means exact match). INDEX(array, position) returns the value at that position. Together they do what XLOOKUP does, and they work in every version of Excel.

Real-Life Scenario

A cinema: MATCH reads your ticket and says "seat 7"; INDEX walks along the row and points at seat 7.

What this formula doesWe want the position of each sale's product in the catalogue.
XTechPlug_Sales_Workbook.xlsx - Excel
After Enter and Fill Down
P2
fx
=MATCH(C2,'Product Catalogue'!$A$2:$A$21,0)
A⋯C⋯P
1Transaction_IDProduct_IDPosition
2TP-0892PRD-01515
3TP-0785PRD-0044
4TP-0210PRD-01818
5TP-0343PRD-0099
6TP-0238PRD-02020
⋮⋮⋮⋮
22TP-0511PRD-01414
⋮⋮⋮⋮
27TP-0454PRD-01414
Filled down from P2 to P1051: 1,050 rows. Rows 2, 3, 4, 5, 6, 22, 27 shown.
Cleaning ProcessSales DataProduct CatalogueStaff Directory
What this formula doesWe want the brand at that position, by putting MATCH inside INDEX.
XTechPlug_Sales_Workbook.xlsx - Excel
After Enter and Fill Down
P2
fx
=INDEX('Product Catalogue'!$D$2:$D$21,MATCH(C2,'Product Catalogue'!$A$2:$A$21,0))
A⋯CD⋯P
1Transaction_IDProduct_IDProduct_NameBrand
2TP-0892PRD-015Thermocool AC 1.5HPThermocool
3TP-0785PRD-004Infinix Hot 40Infinix
4TP-0210PRD-018Anker Power Bank 20KAnker
5TP-0343PRD-009Samsung 43" TVSamsung
6TP-0238PRD-020Logitech Wireless MouseLogitech
⋮⋮⋮⋮⋮
22TP-0511PRD-014LG Washing MachineLG
⋮⋮⋮⋮⋮
27TP-0454PRD-014LG Washing MachineLG
Filled down from P2 to P1051: 1,050 rows. Rows 2, 3, 4, 5, 6, 22, 27 shown.
Cleaning ProcessSales DataProduct CatalogueStaff Directory

PRD-015 is item 15 of the catalogue, and INDEX returns item 15 of the Brand column. The same brands. Like XLOOKUP, it points at columns rather than counting them, so an inserted column does not break it. If your Excel has XLOOKUP, use XLOOKUP; if not, this is your tool.

5. When the Lookup Finds Nothing

Definition

When the value is not in the lookup column, VLOOKUP, XLOOKUP and MATCH all return #N/A: "not available". There are two very different reasons, and they need different fixes.

Real-Life Scenario

You search your contacts for a name and get nothing. Either you never saved that person (a genuinely new contact), or you typed the name wrongly (a mistake to fix). The phone shows the same empty screen for both.

Four new sales arrive on a sheet called New Sales. Look carefully at their Product_IDs:

What this formula doesWe want the price of each new sale's product from the catalogue.
XTechPlug_Sales_Workbook.xlsx - Excel
After Enter and Fill Down
D2
fx
=XLOOKUP(B2,'Product Catalogue'!$A$2:$A$21,'Product Catalogue'!$E$2:$E$21)
AB⋯D
1Transaction_IDProduct_IDPrice
2TP-1101PRD-00475,000
3TP-1102PRD-021#N/A
4TP-1103PRD-017·#N/A
5TP-1104PRD-012420,000
Filled down from D2 to D5: 4 rows. Rows 2, 3, 4, 5 shown.
Cleaning ProcessSales DataProduct CatalogueStaff DirectoryNew Sales

Two #N/A results, for two different reasons. Row 3: PRD-021 is a new product that is not in the catalogue yet. Row 4: PRD-017 is in the catalogue, but this cell has a space after the ID (the red dot), so it does not match exactly.

Fix 1: A Clear Message for Genuinely Missing Items

What this formula doesWe want a readable message instead of #N/A when a product is not in the catalogue, using XLOOKUP's fourth argument.
XTechPlug_Sales_Workbook.xlsx - Excel
After Enter and Fill Down
D2
fx
=XLOOKUP(B2,'Product Catalogue'!$A$2:$A$21,'Product Catalogue'!$E$2:$E$21,"Not in catalogue")
AB⋯D
1Transaction_IDProduct_IDPrice
2TP-1101PRD-00475,000
3TP-1102PRD-021Not in catalogue
4TP-1103PRD-017·Not in catalogue
5TP-1104PRD-012420,000
Filled down from D2 to D5: 4 rows. Rows 2, 3, 4, 5 shown.
Cleaning ProcessSales DataProduct CatalogueStaff DirectoryNew Sales

On older Excel, IFERROR(formula, value) does the same for VLOOKUP or INDEX/MATCH: it returns the formula's result, or the value you give if the formula produces any error. For example =IFERROR(VLOOKUP(B2,'Product Catalogue'!$A$2:$G$21,5,FALSE),"Not in catalogue").

Fix 2: Clean the Data, Do Not Hide It

IFERROR Is Not a Cleaning Tool

Row 4 now says "Not in catalogue", which is false: PRD-017 is the JBL Bluetooth Speaker. The real problem is the trailing space, and the real fix is TRIM, from Week 2. Use the message for items that are genuinely missing; fix the data when the error comes from dirt.

What this formula doesWe want the lookup to ignore stray spaces in the Product_ID, by trimming it before it is looked up.
XTechPlug_Sales_Workbook.xlsx - Excel
After Enter and Fill Down
D2
fx
=XLOOKUP(TRIM(B2),'Product Catalogue'!$A$2:$A$21,'Product Catalogue'!$E$2:$E$21,"Not in catalogue")
AB⋯D
1Transaction_IDProduct_IDPrice
2TP-1101PRD-00475,000
3TP-1102PRD-021Not in catalogue
4TP-1103PRD-017·45,000
5TP-1104PRD-012420,000
Filled down from D2 to D5: 4 rows. Rows 2, 3, 4, 5 shown.
Cleaning ProcessSales DataProduct CatalogueStaff DirectoryNew Sales

Now the speaker finds its price and only PRD-021, which really is missing, says so. That message is now a to-do item: ask procurement to add PRD-021 to the catalogue.

Picture This

Picture two people missing from your contacts: one you never saved, one you saved as "Mamma". You add the first; you fix the spelling of the second. You would never solve both by hiding the empty screen.

Overall Example: A Price Check on Every Sale

In Week 1 you spot-checked five prices against the catalogue by eye. Now check all of them at once:

What this formula doesWe want every sale checked against the catalogue price: OK if the price charged matches, "Price differs" if not, and "Not in catalogue" if the product is missing.
XTechPlug_Sales_Workbook.xlsx - Excel
After Enter and Fill Down
P2
fx
=IF(XLOOKUP(C2,'Product Catalogue'!$A$2:$A$21,'Product Catalogue'!$E$2:$E$21,"Not in catalogue")=G2,"OK","Price differs")
A⋯C⋯G⋯P
1Transaction_IDProduct_IDUnit_PricePrice_Check
2TP-0892PRD-015380,000OK
3TP-0785PRD-00475,000OK
4TP-0210PRD-01828,000OK
5TP-0343PRD-009250,000OK
6TP-0238PRD-02018,000OK
⋮⋮⋮⋮⋮
22TP-0511PRD-014285,000OK
⋮⋮⋮⋮⋮
27TP-0454PRD-014285,000OK
Filled down from P2 to P1051: 1,050 rows. Rows 2, 3, 4, 5, 6, 22, 27 shown.
Cleaning ProcessSales DataProduct CatalogueStaff Directory

All 1,050 sales say OK: every sale was charged exactly the catalogue price. That is the accuracy check from Week 1, finished properly. And a product missing from the catalogue? XLOOKUP returns the text "Not in catalogue", which does not equal G2, so the row says "Price differs": good enough to flag it for a person to look at. Delete column P when you finish.

Practical Exercises

Exercise 1: Very Easy

Use XLOOKUP to fetch each sale's Warranty_Months from the catalogue.

Exercise 2: Simple Application

Write the same lookup with VLOOKUP. Which col_index_num do you need?

Exercise 3: Combination

Use XLOOKUP with the price 18000 to find which product costs N18,000.

Exercise 4: A Small Real-World Problem

On the New Sales sheet, add a Line_Total column: Quantity times the looked-up price, showing "Check" instead of a number when the product is not in the catalogue.

Answers to the exercises

Exercise 1: =XLOOKUP(C2,'Product Catalogue'!$A$2:$A$21,'Product Catalogue'!$G$2:$G$21). Exercise 2: =VLOOKUP(C2,'Product Catalogue'!$A$2:$G$21,7,FALSE). Exercise 3: Logitech Wireless Mouse. Exercise 4: =IFERROR(C2*XLOOKUP(TRIM(B2),'Product Catalogue'!$A$2:$A$21,'Product Catalogue'!$E$2:$E$21),"Check").

Checkpoint

Q1. In =VLOOKUP(C2,'Product Catalogue'!$A$2:$G$21,4,FALSE), what does the 4 mean?

Return the fourth column of the table, counted from the left of the table: Brand.

Q2. Why does VLOOKUP return supplier names after a column is inserted?

The table grows to include the new column, but the column number stays 4, which is now Supplier.

Q3. Why does XLOOKUP survive the same insertion?

It refers to the return column itself, and Excel moves that reference when columns are inserted.

Q4. Why is the tab name written in single quotes?

Because "Product Catalogue" has a space in it.

Q5. A lookup returns #N/A because of a trailing space. Should you use IFERROR?

No. Clean it with TRIM. IFERROR would hide a fixable problem behind a false message.

Tick Before You Move On

  • ☐ I can write VLOOKUP with FALSE and explain all four arguments
  • ☐ I have seen VLOOKUP return the wrong column after an inserted column
  • ☐ I can write XLOOKUP, look to the left, and use its fourth argument
  • ☐ I can write INDEX and MATCH for older Excel
  • ☐ I can tell a genuinely missing item from a dirty one, and fix each correctly
  • ☐ I price-checked all 1,050 sales against the catalogue

Quick Recap

A lookup finds a value in one column and returns the value beside it, often from another tab. VLOOKUP counts columns, so an inserted column silently breaks it, and it cannot look left. XLOOKUP points at the column to return: it survives inserts, looks either way and has a not-found message. INDEX and MATCH do the same job in any version of Excel. #N/A means not found: give a message for genuinely missing items, and clean the data for dirty ones.

Final Scenario

In March, TechPlug's procurement team adds a Supplier column to the Product Catalogue. In April, the monthly report by brand says TechPlug sold nothing from Apple, Samsung or HP.

You open the report and click a brand cell: =VLOOKUP(C2,'Product Catalogue'!$A$2:$H$21,4,FALSE). The 4 now points at Supplier, so every "brand" is a supplier's name. You replace it with an XLOOKUP pointing at the Brand column, and the report is right again. Next time someone inserts a column, nothing will break.

Point at what you want. Never count to it.

Next, Week 4, Virtual 1: lookups into the Staff Directory on your own (zone and manager), and a Data Validation dropdown that stops anyone typing a category that does not exist.

Learn this with a real instructor

Free lessons take you a long way on your own. The full programmes add live classes, assignments, Skill Points and a certificate — built for African students.