VLOOKUP with calculated column index

An excel formula to vlookup with calculated column index

Related Functions

 VLOOKUP with calculated column index

There are times when you may want to use VLOOKUP with a dynamic column index. A common example is when you want to merge two tables, and need to copy a working VLOOKUP formula across several columns without any editing. One way to do this is to use a function like COLUMN.

In the example above, we are using the following formulas to lookup customer data and bring Name and State into the invoice data table. The VLOOKUP formula used for both is identical:


How this formula works

This is a standard "exact match" VLOOKUP formula with one exception: the column index is calculated using the COLUMN function. When the COLUMN function is used without any arguments, it returns a number that corresponds to the current column.

In this case, the first instance of the formula in column E returns 5, since column E is the 5th column in the worksheet. We don't actually want to retrieve data from the 5th column of the customer table (there are only 3 columns total) so we need to subtract 3 from 5 to get the number 2, which is used to retrieve Name from customer data:

COLUMN()-3 = 2 // column E

When the formula is copied across to column F, the same formula yields the number 3:

COLUMN()-3 = 3 // column F

As a result, the first instance gets Name from the customer table (column 2), and the 2nd instance gets State from the customer table (column 3).

You can use this same approach to write one VLOOKUP formula that you can copy across many columns to retrieve values from consecutive columns in another table.

Another way

Another way to calculate a column index for VLOOKUP is to do a two-way VLOOKUP using the MATCH function.

0 votes. 0 / 5