Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

My getLastRow() is giving me as result the last row +2

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 :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading