1

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

enter image description here

new name
  • 15,861
  • 19
  • 68
  • 114
plaridel1
  • 81
  • 6

2 Answers2

1

by .getMaxRows() :

function nbRows(){
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheets()[0];
Logger.log(sheet.getMaxRows());
}
Mike Steelson
  • 14,650
  • 2
  • 5
  • 20
0

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);
}
plaridel1
  • 81
  • 6