HomeGoogle DocsSpreadsheetDynamic Column in Vlookup Importrange Formula in Google Sheets

Dynamic Column in Vlookup Importrange Formula in Google Sheets

Published on

If you use Vlookup, then you must know about the use of the dynamic column in Vlookup Importrange combination in Google Sheets.

The main reason, you can Vlookup an external Google Sheets file with the help of the Google Sheets function Importrange.

In such use, the Importrange output acts as the Vlookup ‘range’. Vlookup accepts this combination without any error.

VLOOKUP(search_key, range, index, [is_sorted])

Dynamic column, what’s that?

In Vlookup you need to provide a column number to return a value or values. This number is called “index”.

Assume you have a two column product price list, in which column A contains the product’s names and B contain its price.

If you want the price of any product by searching in column A, use must use column 2 as the index column in Vlookup.

If the product list is in D1:E (column D and E) instead of A1:B as above (column A and B), then again the index column will be 2. Because column counts start from the first column in the data range.

It’s advisable to make this column number dynamic. I mean auto adjust the column number when you insert new columns in your data range. Here is one example.

dynamic and static column Vlookup

The Normal Vertical Lookup (Vlookup) Formula in Cell D2 (using static index column number):

=vlookup("Banana",A1:B,2,false)

The Dynamic Column Vertical Lookup (Vlookup) Formula in Cell D3 (using dynamic index column number):

=vlookup("Banana",A1:B,column(B1),false)

I have earlier explained this in my tutorial – Dynamic Index Column in Vlookup in Google Sheets.

Also, before going to read further, I suggest you read my tutorial – How to Vlookup Importrange in Google Sheets [Formula Examples]. That post contains some awesome tips.

Why a Dynamic Index Column in Vlookup Importrange is a Must

Suppose you have used the Importrange data, i.e., data in an external Google Sheets file, as the range in Vlookup. The above issue of index column may surfaces here also.

There are more chances of forgetting to update the index number in Vlookup when you make changes in the source (external) file.

So to make a set and forget Vlookup + Importrange, this dynamic index column approach is a must.

How to Refer to a Dynamic Column in Vlookup Importrange in Google Sheets

I have two options right now. Pick the one that you feel convenient for you to follow. See that under the two different subtitles below.

I am going to do my level best to make things easier for you to follow.

Sample data to explain the use of the dynamic index column concept in Vlookup Importrange formula in Google Sheets:

Sample data for learning dynamic column in Vlookup Importrange

Named Ranges as Vlookup Index Column in Google Sheets (Option 1)

See the step by step instructions below.

Settings in the Source File (FILE_A)

Step # 1:

The above sample data is in the source file (call it FILE_A) “Sheet1”. In that file, add a new tab “Sheet2”.

Later I will import the data in “Sheet1” to another Google Sheets file (call it FILE_B) and Vlookup the price in column B in the source.

That means column 2 is our index column. I am going to first make the column number dynamic.

Step # 2:

In FILE_A I have already inserted a new tab “Sheet2”. In cell A1 in that tab, enter the following formula.

=column(Sheet1!B1)

This is a helper tab and helper cell. So we don’t want any other rows or columns in that Sheet.

If you want, you can delete all the other rows and columns in the “Sheet2” tab. Always delete unwanted rows and columns in Google Sheets to enhance Sheets performance.

Step # 3:

Select the cell that contains the above Column formula. Then go to the menu DATA > NAMED RANGES. Name the cell as “price”.

Settings in the Output File (FILE_B)

Time to use the Importrange in FILE_B.

Step # 1:

In cell A1 in FILE_B enter the URL of the FILE_A. Then in cell A2 enter the source data range Sheet1!A1:1000 not, Sheet1!A1:B. Why so? This is because we want to use infinite columns. Then only the dynamic column ID has any effect.

Finally in cell A3 type the Named Range name, i.e., “price”.

If you have any doubt, please check the below screenshot.

Prepare sheet for dynamic column in Vlookup Importrange formula

Step # 2:

In cell B4, enter your search key (product name).

Step # 3:

Now in this step, let me share you how to get a dynamic column in Vlookup Importrange formula in Google Sheets.

Formula:

=vlookup(B4,importrange(A1,A2),importrange(A1,A3),false)
Result showing dynamic column use in Vlookup and imported data

As usual, if you see #REF! Error, that means you have not given ‘Allow Access’ to Importrange.

In that case, first, use any of the Importrange formulas independently and give ‘Allow Access’. You can then delete that formula and use it in the above combo formula.

To test the output, go to FILE_A and insert a new column between A and B. Come back to FILE_B and see the Vlookup Importrange formula automatically adjusts the index column number.

Dynamic Index Column in Importrange + Vlookup Array Formula

We can use the above formula to get the price of multiple products at one go! See the Array Formula in cell C4, which populates an array result.

=ArrayFormula(vlookup(B4:B6,importrange(A1,A2),importrange(A1,A3),false))
Vlookup + Importrange + Dynamic Column - Array Formula

Match formula as Vlookup Index Column in Google Sheets (Option 2)

This is another approach to input dynamic column in Vlookup Importrange formula. This is based on the Match function as the column index. In this in FILE_A no need to create the helper tab ‘Sheet2’.

Here prepare your FILE_B as follows. I have given useful tips on the screenshot itself.

Vlookup + Importrange + Match combo

Here is the non-array Vlookup + Match + Importrange Formula. In this the Match formula returns the dynamic column number, I mean the column number that moves/changes.

=vlookup(B4,importrange(A1,A2),match(A4,importrange(A1,A3),0),false)

In array (multiple search keys) usage, the formula will be as follows. Considering the search keys are in the range B4:B6.

=ArrayFormula(vlookup(B4:B6,importrange(A1,A2),match(A4,importrange(A1,A3),0),false))

Here again, I have used the Match formula to act as the dynamic column ID in Vlookup + Importrange.

How?

The Match formula uses the field label of the Index column as the search key and returns its position in the range. When that column moves, accordingly the Match will return the correct column number.

That’s all. Any doubt, you can ask me in the comments. Enjoy!

Additional Resources:

  1. How to Freeze Cell in Importrange in Google Sheets.
  2. How to Use IMPORTRANGE Function with Conditions in Google Sheets.
  3. Dynamic Sheet Names in Importrange in Google Sheets.
  4. How to Use Query With Importrange in Google Sheets.
  5. Dynamic Column Id in Query Importrange Using Named Ranges.
Prashanth KV
Prashanth KV
Your Trusted Google Sheets and Excel Guide Prashanth KV brings a wealth of experience in Google Sheets and Excel, cultivated through years of work with multinational corporations in Mumbai and Dubai. As a recognized Google Product Expert in Docs Editors, Prashanth shares his expertise through insightful blogging since 2012. Explore his blog for practical tips and guidance on maximizing your spreadsheet skills.

Google Sheets Bar and Column Chart with Target Coloring

To color each data point in the column or bar chart according to the...

Analyzing Column A Between Non-Adjacent Values in Column B: Google Sheets

This tutorial addresses a common scenario encountered in Google Sheets: how to sum, average,...

Excel Word Count: Beyond SUBSTITUTE

You might want to count the number of words in a cell in Excel...

Sum by Quarter in Excel: New and Efficient Techniques

Knowing how to sum by quarter is crucial in Excel because quarterly reporting has...

More like this

Google Sheets Bar and Column Chart with Target Coloring

To color each data point in the column or bar chart according to the...

Analyzing Column A Between Non-Adjacent Values in Column B: Google Sheets

This tutorial addresses a common scenario encountered in Google Sheets: how to sum, average,...

Count Distinct Values in Google Sheets Pivot Table

There is a built-in function for counting distinct values in a Google Sheets Pivot...

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.