简体   繁体   中英

Dynamic cell reference in Google Sheets

在此处输入图片说明

I want to get the salary of Evan. This code is working perfect:

=vlookup("Evan",{A2:A,D2:D},2,0)
>> will output 44444

But how to make the cell reference dynamic? so in =vlookup("Evan",{A2:A,D2:D},2,0) , i want to make the 'D' dynamic. Let assume, this is a big table where we don't know the position of the 'salary' column, so there will be inserting new column (or delete column) to the left of 'salary' column which will push the salary column to left or right. One thing to be sure there's only unique 'salary' header title on the first row, let's assume we have no idea where that column so we will chase it by that 'salary' string.

So the question: how to make the code, so the cell reference to the 'salary' column will not be broken.

There are two ways to accomplish what you want. The following google sheet has both examples in it. https://docs.google.com/spreadsheets/d/1vI3S4k0vGrtIY8iZBgmKDdAYR5yLadasmWw0Jewrl0g/edit?usp=sharing

Example 1: In this example you indicate all the data as the range and utilize the MATCH function to get the index position of the appropriate header.

=VLOOKUP("Evan",A:D,MATCH("Salary",1:1,0),false)

Example 2: This is what you were asking about and can be accomplished by a combination of the following functions: MATCH, ADDRESS, REPT, REGEXTRACT, SUBSTITUTE, and INDIRECT. How it works is detailed in the sheet.

=VLOOKUP("Evan",{A2:A,Indirect(Substitute(REGEXEXTRACT(REPT(Address(1,match("Salary",$1:$1,0),4),2),"[^1]*1[^1]*"),1,"2:"))},2,false)

Cheers!

this will chase the salary column across the sheet:

=VLOOKUP("Evan", {A1:A, INDIRECT(
 ADDRESS(1,         MATCH("Salary", 1:1, 0))&":"&
 ADDRESS(ROWS(A:A), MATCH("Salary", 1:1, 0)))}, 2, 0)

0

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM