Search code examples
arraysgoogle-sheetsgoogle-sheets-formulags-vlookupaddressing

How to pass addresses to Vlookup based on cell values (Google Sheets)


This has me stumped, so I'm hoping somebody who knows the proper functions can help me out.

I am trying to do a VLOOKUP, but I want to pass the Range in based on values in columns.

The Range is on a different sheet than where the formula is, and I want the range's start column to be determined by looking for the value that is at the top of the column the forumla exists in.

For example, in the attached image, the 'Dashboard' sheet has Column A as Sheet, and the top Row has Widgets and Sprockets in the top row.

I want the Formula to be a Lookup for the search key 'Total, and return the value in the cell next to it. I want the Range to start on the sheet specified in Column A, and the Column to be the one with the value that matches the one at the top of the column where the formula is.

So my formula will look like

=VLOOKUP("Total",<INSERT RANGE HERE>,2)

Help would be appreciated.

Link to the Google Sheet:

https://docs.google.com/spreadsheets/d/1H5At3gHeTQUm6PWqeA7MT5xcm5RJ38NK6LyhSWUeaZY/edit?usp=sharing

Thanks Stack Overflow Community

Attached Screenshot


Solution

  • I believe this is what you're looking for.

    On the Dashboard sheet enter these formulas:

    C3:

    =vlookup("Total", indirect($A3&"!C1:D"),2)
    

    D3:

    =vlookup("Total", indirect($A3&"!C1:F"),4)
    

    You can then select C3:D3 and drag down to autofill. I tried using an arrayformula and it didn't work, but I might have been doing it wrong

    ex

    Also make sure to change "Position1" and "Position2" to match the sheet names exactly.

    Edit: I just saw your screenshot. These formulas can also be put into C2 and D2, I just put them next to the sheet names to keep track of what I had to do.


    Edit in response to comment: This was the closest I could get to what you're looking for.

    C3:
    =vlookup("Total", indirect($A3&"!C1:"&ADDRESS(ROW(INDIRECT($A3&"!$C50")),COLUMN()+1)),2)

    D3:
    =vlookup("Total", indirect($A3&"!E1:"&ADDRESS(ROW(INDIRECT($A3&"!$E50")),COLUMN()+1)),2)

    Again, these columns can be dragged and autofilled down with no issues.


    I have the following formula that can be pasted onto the dashboard C3 cell, and then copied across: =address(1,match(C$1,indirect($A3&"!1:1"),0),,,$A3) This will give me the address I want from the Sheet I am trying to reference, i.e. Position01!$C$1 Also, If I use the following formula, I get the value I want as a result: =offset(Position01!$C$1,7,1,1,1) However, If I try to combine the two, I get the error 'Argument must be a range'. =offset(address(1,match(C$1,indirect($A3&"!1:1"),0),,,$A3),7,1,1,1)

    You need to add INDIRECT in front of the first formula when placing it inside of the OFFSET one so that it reads the result address as a range instead of a string:
    =offset(INDIRECT(address(1,match(C$1,indirect($A3&"!1:1"),0),,,$A3)),7,1,1,1)