Search code examples
google-apps-script

How to get the target cell row number in the sheet with Google-apps-script


I want to create a google-apps-script in google sheet.

First I need get the target cell row number, then continue the next step.

I have tried the getRow()and getRowIndex(),all of them return 0, could you tell me what's the right method...

var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheets = ss.getSheets();
var sheet1 = sheets[0];
var cell = sheet1.getActiveCell();
var SelectRow = cell.getRow();
Logger.log("SelectRow :" & SelectRow);

For Example: Example

I want to return a number 2.

Thank you very much in advance.


Solution

  • The problem is Logger.log("SelectRow :" & SelectRow);. Use + instead of & for string concatenation and your variable will be displayed properly.

    use:

    Logger.log("SelectRow :" + SelectRow);

    or this:

    Logger.log("SelectRow : %s", SelectRow);