With "lastRow" one can get the last row in a sheet. Sometimes you need the last row of a specific column. Google Apps script das not provide this function. There are around 5 questions and solutions already here on the site, but all have some specific code wrapped around it.
I took the solution what i think is the fastest in most cases - you start looking at the end of the sheet and look backwards in the column you specified - and made a clean function out of it.
So this is a contribution for beginners to copy paste this - the argument "RowNumber" is the column you want to look at as a number: 0 is A, 1 is B, 2 is C etc. The function returns the last row as a number ("4")
Because i am on day 3 as a apps script user, my question is: if this is not the fastest and cleanest way to do it, or the script does not work properly on some circumstances, please tell me. for my usecase it works perfect.
function getLastColumnRow(RowNumber, sheet) {
var data = sheet.getDataRange().getValues();
var numRows = data.length;
// loop from bottom to top for last row in given row "RowNumber"
while( data[numRows - 1][RowNumber] == "" && numRows > 0 ) {
numRows--;
}
return numRows
}