Created
May 15, 2012 11:39
-
-
Save johnwards/2701061 to your computer and use it in GitHub Desktop.
get the value of last row in a sheet in google docs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Your function produces an error. This works.