How to Get the Last Row of Specific Column in Google Apps Script

Lately I've been working on a Google Apps Script to get user information about Twitter users into a Google Sheet. Since Google has a maximum execution time of 5 minutes, you can't have a script run continuously (especially while your calling an API that uses throttling) to fill up all of your rows. I've had to set up triggers in my app, but to do so, you have to read the last row that was written to each time the trigger runs. Turns out, this isn't so easy using a google Sheet with Google Apps Script since Sheets tend to bug out and so the default getLastRow() function doesn't always report the correct last function. The following function, however, will (column parameter that must be passed is the string letter of the column such as "A", "B", "C", etc...):

function getLastRow(column) {

var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheetByName("xyz");
var range = sheet.getRange(column + "1:" + column);
var values = range.getValues();
var newarr = [];
var count = 0;
for (var i = 0; i < range.getLastRow(); i++) {
if (values[i][0]) {
return newarr.length;

I've written another pretty hacky workaround that doesn't require a loop. It simply copies the specific row you need the last row of to a temporary sheet, reads the last row of that sheet, saves it, then destroys the temporary sheet. So, without further ado, here is the code for you to use, modify, distribute or destroy!

function getLastRow(column){
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheetByName("Sheet1");
var range = sheet.getDataRange();
if (range.getNumColumns() > 1) {
 var sheet2 = ss.getSheetByName("xyz");
 sheet.getRange(column + "1:" +column).copyTo(sheet2.getRange("A1:A"));
 var last = sheet2.getLastRow();
 return last;
 } else return 0;

Just a little note: The column variable needs to be string value of the specific column you want the last row for ("A", "B", "C", etc...).