I’m trying to use lastRow(); but its giving me the the last row + 2 rows and I cant find the reason.
¿Can anyone take a quick look and tell me why?
Google Sheet Example
function myFunction() {
var originSpreadSheet = SpreadsheetApp.getActive();
var originSheet = originSpreadSheet.getSheetByName("Sheet1");
var datos = originSheet.getRange(4,5,originSheet.getLastRow(),4).setBackground('red');
console.log(datos.getA1Notation());
}
>Solution :
Change this
var datos = originSheet.getRange(4, 5, originSheet.getLastRow()-3, 4).setBackground('red');
the third argument is the number of rows and not the final row, since you are beginning at row #4, you have to minus by 3