1

I need to get the last row of a specific column. I tried

getLastRow

but it seems to look at all columns, not just one. Then I tried

sheet.getRange(range).getLastRow

and it started after the range I specified. Can you specify a range with getlastRow?

Evan Sullivan
  • 83
  • 2
  • 9
  • This post should answer your question: https://stackoverflow.com/questions/17632165/determining-the-last-row-in-a-single-column – Rick Jan 07 '20 at 19:34

2 Answers2

1

I like wrapping it up with defaults so that I can use it in a variety of ways.

function getColumnHeight(col,sh,ss) {
  var ss=ss || SpreadsheetApp.getActive();
  var sh=sh || ss.getActiveSheet();
  var col=col || sh.getActiveCell().getColumn();
  return sh.getRange(1,col,sh.getLastRow(),1).getValues().filter(String).length;
}
Cooper
  • 59,616
  • 6
  • 23
  • 54
0

Here the script to find the last row for the spesific column:

function GetLastColumn() 
{
   var Col="A"; //Column that will find the last row not empty, can be assigned as parameter
   var sheet = SpreadsheetApp.getActive().getSheetByName('Sheet2');
   var yourRange = sheet.getRange(Col + 1).offset(sheet.getLastRow()-1, 0); //+1 spare 1 row after last row
   var rsltRange = yourRange.getNextDataCell(SpreadsheetApp.Direction.UP);       
   Logger.log(rsltRange.getA1Notation());
};
user11982798
  • 1,878
  • 1
  • 6
  • 8