Using google spreadsheets is there a way to evaluate a cell value as the row in a lookup operation? For example rather than =D2 to grab the value of D2, I want to evaluate the value of a cell and use it as the row to lookup another cell. I've looked at the google spreadsheet formula documentation and haven't been able to find a solution.
The below pseudocode illustrates what I'm trying to do.
A B C D 1 D 2 =[B1]2 10 3 =[B1]3 9 4 =[B1]4 8
Given the value of B1 is "D" I want cells B2, B3, and B4 to resolve to 10, 9, and 8 respectively.
When you need to construct a formula instead of directly type a formula, use the INDIRECT function. It turns text strings into a cell reference. For example, if you need to have a formula that references a column of data. You may want the same formula for a different column.
To extract text from the middle of a text string, we can use the RIGHT, SEARCH and LEN functions to get the text from the right side of the string, and then use the MID and LEN functions to get the text in the middle. We will also incorporate the TRIM function to trim any spaces on either side of the text string.
Using the IF Function The IF function can be used on its own in a single logical test, or you can nest multiple IF statements into a single formula for more complex tests. To start, open your Google Sheets spreadsheet and then type =IF(test, value_if_true, value_if_false) into a cell.
You might be looking for something like this:
=INDIRECT(INDEX(B$1;1;1)&ROW())
INDEX(B$1;1;1)
gets content of B1 cell (the 1;1 is obligatory parameter, since you can feed INDEX with range and means: 1st row in range;1st column in range which is D
ROW()
returns current row number, be it 2, 3 etc.INDIRECT(reference)
returns reference to a cell or an area (in text form) for which to return the contents.see https://support.google.com/drive/table/25273?hl=en
Still, depending on what is the original problem, there might be better solutions. Above one is just straightforward answer to your question.
Bearing in mind the correctness and helpfulness of PsychoFish's advice on the use of INDEX()
with INDIRECT()
, and on the limited usefulness of any one solution for all problems, I think the following formula will work as well in this particular case:
=INDIRECT(B$1&Row())
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With