David Stockdale's Scrapcode

Get Last Row in A Column Using Google Apps Script

Another simply bit of code that’s worth writing down: how to get the last row in a specific column using Google Apps Script.

Here’s the code:

var sheet = SpreadsheetApp.openById("X").getSheetByName('X'); //Get Sheet By Name
var vals= sheet.getRange("A1:A").getValues(); //Get Values Of Column
var lastRow = vals.filter(String).length; //Get Last Row
Logger.log(lastRow);

Which simply gets a specific column in a specific sheet and then gets it’s values before determining their length.

This is the quickest and easiest way to get the last row in a column.

Hopefully this will make someone’s google search a bit quicker.

Leave a like or a comment if it helped!

Leave a Reply