How to get value from a neighboring cell using Google Script in Google Spreadsheet?

I apologize if this was asked before, but I was looking for an example, and unfortunately I can not find the answer, so I ask here.

If I have a special function in a Google spreadsheet, how can I get the cell value if the content is dynamically generated. I can get the value when it is fixed, but not dynamic.

+5
source share
1 answer

Here's an example of getting an adjacent cell value, be it dynamic (created using a function or a flat value)

function getAdjacentValue() {
  var range = SpreadsheetApp.getActiveRange();
  var col = range.getColumn();
  var row = range.getRow();
  var range2 = SpreadsheetApp.getActiveSheet().getRange(row,col+1);
  return range2.getValue();
}
+12
source

All Articles