Reputation: 83
How can I modify the below to give me the last row of column A. At the moment it calculates the last row of all the columns.
function Test() {
var ss = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
var lr = ss.getLastRow();
Browser.msgBox(lastRow);
}
I saw the below in another post and tried replacing mySheet with ss but that didn't give me the correct output.
var lastCell = mySheet.getRange(mySheet.getLastRow(),1).getNextDataCell(
SpreadsheetApp.Direction.UP);
Upvotes: 3
Views: 132
Reputation: 2331
Try this -
function Test() {
var ss = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
var colAValues = ss.getRange("A:A").getValues().filter(function(el){
return el != "";
});
var lr = colAValues.length;
Browser.msgBox(lr); // replaced "lastRow" with "lr"
}
Hope this helps but do please let know in case it doesn't :)
Upvotes: 2