public
Last active

get the value of last row in a sheet in google docs

  • Download Gist
lastValue.js
JavaScript
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
function lastValue(column) {
var parts = column.split("!");
if (parts.length == 2) {
var sheetName = parts[0];
var column = parts[1];
var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName(sheetName);
} else {
var column = parts[0];
var sheet = SpreadsheetApp.getActiveSheet();
}
var lastRow = sheet.getMaxRows();
var values = sheet.getRange(column + "1:" + column + lastRow).getValues();
 
for (; values[lastRow - 1] == "" && lastRow > 0; lastRow--) {}
return values[lastRow - 1];
}

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.