Home > Net >  My getLastRow() is giving me as result the last row 2
My getLastRow() is giving me as result the last row 2

Time:07-25

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());  
}

CodePudding user response:

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

  • Related