You have a product table and you need to pull five columns for each ID: name, category, price, stock and supplier. The usual way is to write a VLOOKUP, copy it to the right, and then fix the column number in every single cell: 2, 3, 4, 5, 6. With 20 columns that's 20 manual edits, and 20 chances to type the wrong number.
There is a better way: one formula that you write once and copy both down and across.
=VLOOKUP($A9, $A$1:$F$6, COLUMNS($A$1:B1), 0)
The slow way: a different formula in every column
This is what most people do. Each cell in row 9 has its own column number typed by hand:
{"cells": {"A1": "ID", "B1": "Product", "C1": "Category", "D1": "Price", "E1": "Stock", "F1": "Supplier", "A2": "P01", "B2": "Mouse", "C2": "Accessories", "D2": 25, "E2": 140, "F2": "Logi", "A3": "P02", "B3": "Keyboard", "C3": "Accessories", "D3": 45, "E3": 85, "F3": "Keytron", "A4": "P03", "B4": "Monitor", "C4": "Displays", "D4": 320, "E4": 22, "F4": "ViewMax", "A5": "P04", "B5": "Headphones", "C5": "Audio", "D5": 60, "E5": 64, "F5": "Sonic", "A6": "P05", "B6": "Webcam", "C6": "Video", "D6": 80, "E6": 37, "F6": "ClearCam", "A8": "ID", "B8": "Product", "C8": "Category", "D8": "Price", "E8": "Stock", "F8": "Supplier", "A9": "P03", "B9": "=VLOOKUP($A9,$A$1:$F$6,2,0)", "C9": "=VLOOKUP($A9,$A$1:$F$6,3,0)", "D9": "=VLOOKUP($A9,$A$1:$F$6,4,0)", "E9": "=VLOOKUP($A9,$A$1:$F$6,5,0)", "F9": "=VLOOKUP($A9,$A$1:$F$6,6,0)"}, "formats": {"D2:D6": {"fmt": "currency", "dec": 0}, "D9": {"fmt": "currency", "dec": 0}}, "focus": "B9", "rows": 10, "note": "Click B9, C9, D9… — five cells, five different formulas."}
It works, but nothing here can be copied. Copy B9 to the right and you get "Monitor" five times, because the 2 doesn't change. And if someone inserts a column into the table, every hard-coded number after it is silently wrong.
One formula for the whole block
Here the same formula sits in every cell of B9:F11. It was typed once in B9 and copied to the rest:
{"cells": {"A1": "ID", "B1": "Product", "C1": "Category", "D1": "Price", "E1": "Stock", "F1": "Supplier", "A2": "P01", "B2": "Mouse", "C2": "Accessories", "D2": 25, "E2": 140, "F2": "Logi", "A3": "P02", "B3": "Keyboard", "C3": "Accessories", "D3": 45, "E3": 85, "F3": "Keytron", "A4": "P03", "B4": "Monitor", "C4": "Displays", "D4": 320, "E4": 22, "F4": "ViewMax", "A5": "P04", "B5": "Headphones", "C5": "Audio", "D5": 60, "E5": 64, "F5": "Sonic", "A6": "P05", "B6": "Webcam", "C6": "Video", "D6": 80, "E6": 37, "F6": "ClearCam", "A8": "ID", "B8": "Product", "C8": "Category", "D8": "Price", "E8": "Stock", "F8": "Supplier", "A9": "P03", "A10": "P01", "A11": "P05", "A12": "P02", "B9": "=VLOOKUP($A9,$A$1:$F$6,COLUMNS($A$1:B1),0)", "C9": "=VLOOKUP($A9,$A$1:$F$6,COLUMNS($A$1:C1),0)", "D9": "=VLOOKUP($A9,$A$1:$F$6,COLUMNS($A$1:D1),0)", "E9": "=VLOOKUP($A9,$A$1:$F$6,COLUMNS($A$1:E1),0)", "F9": "=VLOOKUP($A9,$A$1:$F$6,COLUMNS($A$1:F1),0)", "B10": "=VLOOKUP($A10,$A$1:$F$6,COLUMNS($A$1:B2),0)", "C10": "=VLOOKUP($A10,$A$1:$F$6,COLUMNS($A$1:C2),0)", "D10": "=VLOOKUP($A10,$A$1:$F$6,COLUMNS($A$1:D2),0)", "E10": "=VLOOKUP($A10,$A$1:$F$6,COLUMNS($A$1:E2),0)", "F10": "=VLOOKUP($A10,$A$1:$F$6,COLUMNS($A$1:F2),0)", "B11": "=VLOOKUP($A11,$A$1:$F$6,COLUMNS($A$1:B3),0)", "C11": "=VLOOKUP($A11,$A$1:$F$6,COLUMNS($A$1:C3),0)", "D11": "=VLOOKUP($A11,$A$1:$F$6,COLUMNS($A$1:D3),0)", "E11": "=VLOOKUP($A11,$A$1:$F$6,COLUMNS($A$1:E3),0)", "F11": "=VLOOKUP($A11,$A$1:$F$6,COLUMNS($A$1:F3),0)"}, "formats": {"D2:D6": {"fmt": "currency", "dec": 0}, "D9:D12": {"fmt": "currency", "dec": 0}}, "focus": "B9", "rows": 13, "note": "Row 12 is empty: select B11:F11 and drag the small square in the corner down one row. Or change an ID in column A."}
Try it: row 12 has an ID but no formulas. Select B11:F11 and drag the fill handle (the small square in the bottom-right corner of the selection) down one row. All five values appear, with no editing.
How it works: three kinds of references
The formula has three parts, and each uses a different kind of reference on purpose.
| Part | Reference type | What happens when you copy |
|---|---|---|
$A9 |
Mixed: column locked, row free | Right: stays in column A. Down: moves to A10, A11… |
$A$1:$F$6 |
Absolute: fully locked | Never moves. Always the same table |
COLUMNS($A$1:B1) |
Expanding: start locked, end free | Right: grows to $A$1:C1, $A$1:D1… |
0 |
— | Exact match (same as FALSE) |
1. $A9, the lookup value
The dollar sign is only before the letter. Copy the formula to the right and it still looks up the ID in column A. Copy it down and the row changes to 10, 11, 12, so each row looks up its own ID. Without the $, the second column would look up the product name instead of the ID and return #N/A.
2. $A$1:$F$6, the table
Fully locked with four dollar signs. Wherever the formula goes, it searches the same table.
3. COLUMNS($A$1:B1), the column number that counts itself
This is the trick. COLUMNS returns how many columns a range has. The range $A$1:B1 starts at a locked cell and ends at a free one, so it gets one column wider with every step to the right:
| Formula in | The range becomes | COLUMNS returns | VLOOKUP returns |
|---|---|---|---|
| B9 | $A$1:B1 |
2 | Product |
| C9 | $A$1:C1 |
3 | Category |
| D9 | $A$1:D1 |
4 | Price |
| E9 | $A$1:E1 |
5 | Stock |
| F9 | $A$1:F1 |
6 | Supplier |
Copy down and the range becomes $A$1:B2, $A$1:B3… It gets taller, but it still has 2 columns, so the result doesn't change. Only the width matters.
The rule: the range inside COLUMNS starts at the first column of the lookup table (locked with $) and ends at the column you want to return (not locked).
The same formula in a real file
Your table doesn't have to start in A1. In one of my working files the table sits in I11:N15 and the IDs to look up are in column Q, so the formula is:
=VLOOKUP($Q12, $I$11:$N$15, COLUMNS($I$11:J11), 0)
Same three parts: $Q12 is the mixed lookup value, $I$11:$N$15 the locked table, and COLUMNS($I$11:J11) returns 2 in the first cell and grows as you copy right.
Commas or semicolons? This article uses commas between arguments. If your Excel uses semicolons (common with European regional settings), write
=VLOOKUP($Q12;$I$11:$N$15;COLUMNS($I$11:J11);0).
Why COLUMNS and not something else?
A typed number (2, 3, 4) can't be copied and breaks silently when a column is inserted.
COLUMN() returns the column number of the cell the formula is in. COLUMN()-5 may give the right result today, but it depends on where the formula sits. Move the block or insert a column in front of it and every result shifts.
COLUMNS($A$1:B1) depends only on the table itself. Insert a column inside the table and Excel widens the range for you. Move the results anywhere and it still works.
When the columns are in a different order: MATCH
The COLUMNS trick assumes you want the columns in the same order as the source table. If you want only some of them, or in another order, let MATCH find each column by its header:
=VLOOKUP($A9, $A$1:$F$6, MATCH(B$8, $A$1:$F$1, 0), 0)
MATCH(B$8, $A$1:$F$1, 0) looks for the header text from row 8 in the table's header row and returns its position. Note the mixed reference B$8: this time the row is locked, so every row reads the header above it, while the column moves as you copy right.
{"cells": {"A1": "ID", "B1": "Product", "C1": "Category", "D1": "Price", "E1": "Stock", "F1": "Supplier", "A2": "P01", "B2": "Mouse", "C2": "Accessories", "D2": 25, "E2": 140, "F2": "Logi", "A3": "P02", "B3": "Keyboard", "C3": "Accessories", "D3": 45, "E3": 85, "F3": "Keytron", "A4": "P03", "B4": "Monitor", "C4": "Displays", "D4": 320, "E4": 22, "F4": "ViewMax", "A5": "P04", "B5": "Headphones", "C5": "Audio", "D5": 60, "E5": 64, "F5": "Sonic", "A6": "P05", "B6": "Webcam", "C6": "Video", "D6": 80, "E6": 37, "F6": "ClearCam", "A8": "ID", "B8": "Price", "C8": "Supplier", "D8": "Product", "A9": "P03", "A10": "P01", "A11": "P05", "B9": "=VLOOKUP($A9,$A$1:$F$6,MATCH(B$8,$A$1:$F$1,0),0)", "C9": "=VLOOKUP($A9,$A$1:$F$6,MATCH(C$8,$A$1:$F$1,0),0)", "D9": "=VLOOKUP($A9,$A$1:$F$6,MATCH(D$8,$A$1:$F$1,0),0)", "B10": "=VLOOKUP($A10,$A$1:$F$6,MATCH(B$8,$A$1:$F$1,0),0)", "C10": "=VLOOKUP($A10,$A$1:$F$6,MATCH(C$8,$A$1:$F$1,0),0)", "D10": "=VLOOKUP($A10,$A$1:$F$6,MATCH(D$8,$A$1:$F$1,0),0)", "B11": "=VLOOKUP($A11,$A$1:$F$6,MATCH(B$8,$A$1:$F$1,0),0)", "C11": "=VLOOKUP($A11,$A$1:$F$6,MATCH(C$8,$A$1:$F$1,0),0)", "D11": "=VLOOKUP($A11,$A$1:$F$6,MATCH(D$8,$A$1:$F$1,0),0)"}, "formats": {"D2:D6": {"fmt": "currency", "dec": 0}, "B9:B11": {"fmt": "currency", "dec": 0}}, "focus": "B9", "rows": 12, "note": "Change the header in C8 to Stock or Category — the column follows the header."}
The output headers must match the table headers exactly. Change C8 to "Stock" and the whole column switches. This is the version I use in reports: nobody has to count columns, ever.
Common mistakes
- No
$before the lookup column.A9instead of$A9: the first column works, the rest return#N/A. - Locking the end of the COLUMNS range.
COLUMNS($A$1:$B$1)is always 2, so every column returns the same value. - Starting COLUMNS at the wrong column. The range must start at the table's first column. Start one column later and every result is shifted by one.
- Copying further than the table. A table with 6 columns has no 7th. One step too far to the right gives
#REF!. - Leaving out the last argument. Without
0(or FALSE), VLOOKUP does an approximate match and can return a value from the wrong row without any error. Always write the0. - IDs that only look the same.
"P03 "with a trailing space or a number stored as text returns#N/A. Clean the data withTRIM.
To show a friendly message instead of #N/A when an ID doesn't exist, wrap the formula in IFERROR:
=IFERROR(VLOOKUP($A9, $A$1:$F$6, COLUMNS($A$1:B1), 0), "Not found")
If you have Excel 365: XLOOKUP
In Microsoft 365 and Excel 2021+, XLOOKUP can return several columns at once. One formula in B9 spills across the whole row:
=XLOOKUP(A9, $A$2:$A$6, $B$2:$F$6)
It's shorter, and it can look to the left, which VLOOKUP can't. But VLOOKUP with COLUMNS works in every Excel version, and it's still what you'll find in most company files, so it pays to know both.