Excel Lookup Table Examples: VLOOKUP, XLOOKUP & INDEX-MATCH
In this article
An Excel lookup table lets you type a key — a product code, an employee ID, a region name — into one cell and have Excel pull the matching value from another table automatically. The quickest modern version is XLOOKUP: put your lookup value in one cell, point XLOOKUP at the key column in your table, point it at the results column, and it returns the match. If your version of Excel does not have XLOOKUP, INDEX-MATCH does the same job, and VLOOKUP remains the most widely recognised option though it is the least flexible of the three. This guide walks through worked examples of each, then covers the errors that cause most lookup failures.
What You'll Need
- A version of Excel that supports your chosen function: XLOOKUP is available in Microsoft 365 and newer perpetual versions; INDEX-MATCH and VLOOKUP work in essentially every version, including older desktop releases.
- A source table (sometimes called the lookup table) with one column of unique keys and one or more columns of values to return. Keys should be text or numbers, not a mix.
- A place to put the formula, ideally with the lookup value in its own cell rather than typed inside the formula — you can then copy the formula down a column.
- Clean data: no leading or trailing spaces, no merged cells inside the table, and no duplicated keys unless you understand which match you want.
Step-by-Step
- Lay out the data. Assume a price table occupying
A1:C6: column A holds product codes, column B holds product names, column C holds prices. Row 1 contains headers (Code, Product, Price) and rows 2 to 6 hold five products. In another cell — sayE2— type the code you want to look up. The table headers and the lookup value are what make the formula readable later, so add them before writing any formula. - Write the XLOOKUP (simplest route). In
F2enter=XLOOKUP(E2,A2:A6,C2:C6). That reads: find the value in E2 within the code column, then return the value from the same row in the price column. Because XLOOKUP points at whole columns rather than counting columns to the right, you can insert a column into the table later without breaking the formula. Press Enter and confirm the returned price matches the product you typed. - Add a friendly message for misses. XLOOKUP's fourth argument replaces the error with your own text:
=XLOOKUP(E2,A2:A6,C2:C6,"Code not found"). This is far tidier than wrapping the formula in IFERROR, and it makes a missing code obvious to whoever reads the sheet next. - Return two values at once. If you want both the product name and the price, select two adjacent cells, for example
F2:G2, and enter=XLOOKUP(E2,A2:A6,B2:C6)before pressing Ctrl+Shift+Enter in older versions or just Enter in Microsoft 365. The return range now spans two columns and XLOOKUP spills both values across the selection. This replaces the old habit of writing a separate VLOOKUP with a different column index for each field. - Do the same job with INDEX-MATCH. In any cell, enter
=INDEX(C2:C6,MATCH(E2,A2:A6,0)). MATCH finds the row position of the code inside A2:A6 (the zero means exact match), and INDEX returns the value at that position inside C2:C6. The two ranges must be the same length, or you will get wrong answers rather than an error. - Do the same job with VLOOKUP. Enter
=VLOOKUP(E2,A2:C6,3,FALSE). E2 is the lookup value, A2:C6 is the whole table, 3 is the column number counted from the first table column (price is third), and FALSE forces an exact match. Copy this formula down a list of codes; unless you have locked the table with dollar signs ($A$2:$C$6) the range will drift as you copy and the lower rows will start returning errors. - Lock the table by absolute or structured reference. Either press F4 after selecting
A2:C6in the formula to produce$A$2:$C$6, or convert the table to an Excel Table (Ctrl+T) and refer to it by name, such as=XLOOKUP(E2,Products[Code],Products[Price]). Structured references grow automatically when you add rows to the table, which saves editing the formula range every month. - Test the edge cases. Type a code that does not exist and check that you get your custom message, not a bare #N/A. Type a code with lowercase letters when the table uses uppercase and confirm the match still works (these functions are not case-sensitive). Try a code with a trailing space pasted from another system and see whether it fails — if it does, that is a data cleaning issue, not a formula issue.
Common Mistakes
- Leaving VLOOKUP's last argument blank. The default is approximate match (TRUE), which returns the nearest lower value rather than the exact one. Always type FALSE for exact matching unless you deliberately want a banded lookup such as tax brackets, in which case the first column must be sorted ascending.
- Counting the VLOOKUP column from the wrong place. The index number counts from the first column of the range you selected, not from column A of the sheet. If your range starts at B, a value in column C is index 2, not 3.
- Looking left with VLOOKUP. VLOOKUP cannot return a value to the left of the key column. Use INDEX-MATCH or XLOOKUP instead — no column reordering required.
- Mismatched data types. A code stored as text (often from a CSV import or a system export) will not match the same digits stored as a number, and vice versa. The green triangle warning in the corner of a cell usually flags this. Convert one side with VALUE or TEXT so both agree.
- Hidden spaces and non-breaking spaces. Values pasted from web pages or exported systems often carry invisible characters. TRIM removes ordinary spaces; for non-breaking spaces you may need SUBSTITUTE with CHAR(160). Clean the key column once and the lookups stop failing.
- Duplicate keys. If two rows share a code, XLOOKUP and VLOOKUP return the first match, MATCH returns the first position. That may be acceptable, but you should know it is happening rather than assume the wrong row was never selected.
- Ranges of different lengths in INDEX-MATCH. The MATCH range and the INDEX range must line up row for row. A one-row offset shifts every result silently.
Tips
- Keep the lookup table on its own sheet and convert it to an Excel Table so it expands when rows are added.
- Nest one lookup inside another when your table holds a second layer of information, for example using XLOOKUP to fetch a region code, then a second XLOOKUP to fetch the regional manager for that code.
- For banded lookups — commission tiers, shipping weight bands — XLOOKUP's match mode argument set to -1 or 1 gives the next smaller or next larger item, and it does not require the table to be sorted the way VLOOKUP does.
- Give the lookup value its own input cell and protect the formula cells, so colleagues cannot overwrite the logic.
- Name the key column with a clear header and avoid symbols in header text; structured references break if the header contains certain characters.
Troubleshooting
If you see #N/A, the key was not found. Check for spaces, text-versus-number storage, and that the key really exists in the table. If you see #REF!, a range has been deleted or the VLOOKUP column number is larger than the table width. If you see #VALUE!, one of the arguments is the wrong type — often an index number typed as text.
If the formula returns the wrong row's value, suspect a mismatched range length in INDEX-MATCH or an unlocked table range that shifted while you copied the formula down. Select the formula, press F2, and inspect which range Excel is highlighting — the coloured outlines show exactly what each argument refers to. If the result looks right but formats wrongly (a date showing as a serial number), the source cell format is the culprit: copy the format with Format Painter or set the cell number format to match.
If a formula that used to work suddenly fails after rows were inserted, an Excel Table reference will normally survive while a plain range will not. Rebuild the formula using the table name and it will keep working through future edits.
Frequently Asked Questions
Should I use VLOOKUP or XLOOKUP?
Use XLOOKUP if your Excel version has it. It searches in either direction, defaults to exact matching, returns multiple columns at once and has a built-in not-found argument. VLOOKUP is fine for simple left-to-right exact lookups on older versions.
Why does my VLOOKUP return the wrong value with no error?
Almost always an approximate match. The fourth argument was left empty or set to TRUE while the key column was unsorted, so Excel picked the nearest lower value. Set it to FALSE for exact matching.
Can a lookup table return a value from a column to the left?
Not with VLOOKUP. Use INDEX-MATCH or XLOOKUP, both of which can return any column regardless of where the key sits.
How many columns can a lookup table have?
As many as you need; the practical limit is how fast the sheet recalculates. Keep the table compact, avoid whole-column references in thousands of rows, and the lookup stays responsive.
Does a lookup table have to be sorted?
Only for approximate matching, such as banded values. Exact-match lookups work on unsorted data.