How to get the last blank row of the entire active sheet for google app script

Viewed 36

How to get the value of the last row number of an active sheet using google app script?

enter image description here

2 Answers

by .getMaxRows() :

function nbRows(){
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheets()[0];
Logger.log(sheet.getMaxRows());
}

Based from answer https://stackoverflow.com/a/9102463/1677912

function getLastSheetRowByColumnArray() {
  var column = sheet.getRange('A:A');
  var values = column.getValues(); // get all data in one call
  var ct = 0;
  while ( values[ct] && values[ct][0] == "" || values[ct] && values[ct][0] != "" ) {
    ct++;
  }
  return (ct);
}
Related