简体   繁体   中英

Google Sheet: how to get value of another cell on the same row?

I am looking for a formula:

  1. If I put it in a cell, for example C2, it will return the value in A2
  2. I can't simply put =A2 because column A could be moved to another column

I am trying to use named range to do this. I have created a named range( teacher_Names ) for A1:A. It is not hard to get the value using app script

function getTeacherNameOnTheSameRow(row) {
  let ss =  SpreadsheetApp.getActive();
  let values = ss.getRangeByName('teacher_Names').getValues();
  return values[row-1];
}

I can just put =getTeacherNameOnTheSameRow(Row()) in cells in Column C, and no matter which column I move column A to, it will work.

My question is, is there a way to do this without app script?

I believe your current situation and goal as follows.

  • The column "A" has the named range of teacher_Names .
  • You have a Google Apps Script of custom function, and the script works.
  • You want to achieve the custom function as the built-in function without using Google Apps Script.
  • For example, when you put the built-in function to the row 5 of the column "C", you want to retrieve the value of the row 5 of the column "A" to the column "C".

In this case, how about the following formula?

Sample formula:

Please put the following formula to the column "C". By this, the column "A" of the named range teacher_Names is retrieved with the same row.

=teacher_Names
Result:

在此处输入图像描述

Note:

  • For example, when you put the formula of =ARRAYFORMULA(teacher_Names) to the cell "C1", you can see the values of the column "A" to the column "C".
  • Also, in this case, even when the column "A" is moved to other column, the values are kept.

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