Reputation: 159
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);
I want to return a number 2.
Thank you very much in advance.
Upvotes: 3
Views: 33774
Reputation: 1
What about this:
function findRow(sheetName,ColumnIndex,Value) {
const ss = SpreadsheetApp.getActiveSpreadsheet();
const sheet = ss.getSheetByName(sheetName);
var LastRow = sheet.getLastRow();
const values = sheet.getRange(1,ColumnIndex,LastRow,1).getValues()
const isRow = (element) => element[0] === Value;
var Rownumber = values.findIndex(isRow);
return (Rownumber+1)
}
Upvotes: 0
Reputation: 2717
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);
Upvotes: 3
Reputation: 508
Please try this -
var currRow = SpreadsheetApp.getActiveSheet().getActiveCell().getRow();
Logger.log("SelectRow :" & SelectRow);
Upvotes: 6