Sylvain
Sylvain

Reputation: 31

How to get value of the cell under the current cell with Google Script?

I can't find an option that could look like

var spreadsheet = SpreadsheetApp.getActive();
var sheet = spreadsheet.getActiveSheet(); 
sheet.getRange(sheet.getCurrentCell() + 1,1).getValue())

Upvotes: 3

Views: 3583

Answers (1)

Kristkun
Kristkun

Reputation: 5953

Based on my understanding, you want to get the value of the cell below the current cell (+1 row of the current cell).

OPTION 1:

You can modify your current code like this:

sheet.getRange(sheet.getCurrentCell().getRow() + 1,1).getValue()

You need to get the row index of the current cell first using Range.getRow(), then increment it by 1.


OPTION 2:

You can use Range.offset(rowOffset, columnOffset) to go into the next row then get its value using Range.getValue()

Sample Sheet:

enter image description here

Sample Code:

function myFunction(){

  var spreadsheet = SpreadsheetApp.getActive();
  var sheet = spreadsheet.getActiveSheet()
  Logger.log(sheet.getCurrentCell().offset(1,0).getValue());
}

Output:

enter image description here

Upvotes: 2

Related Questions