Analytics

Google Apps Script Tip #1: Finding the last row

I’ve been building some custom reports for Portent in Google Spreadsheets. They do fun stuff like grab Google Analytics data, insert data from other APIs and such.

One thing that nearly drove me batty, though, was figuring out how to automatically add a new row below the last row with data.
Turns out, Google App Script has it’s own nifty command, called getLastRow. Here’s how you do it:

function FindRows() {
range = SpreadsheetApp.getActiveSheet().getLastRow();
return range;
}

That’s it. It’ll return the value range. That value is the number of the last row on the sheet that has data. You can then pass that back to other functions to start adding new rows in the right place, delete rows, etc..

If this is all gibberish, fear not. Marketing Ian will be back Monday. Today is Nerd Ian.

CEO & Founder

Ian Lurie is CEO and founder of Portent and the EVP of Marketing Services at Clearlink. He's been a digital marketer since the days of AOL and Compuserve (25 years, if you're counting). He's recorded training for Lynda.com, writes regularly for the Portent Blog and has been published on AllThingsD, Smashing Magazine, and TechCrunch. Ian speaks at conferences around the world, including SearchLove, MozCon, Seattle Interactive Conference and ad:Tech. He has published several books about business and marketing: One Trick Ponies Get Shot, available on Kindle, The Web Marketing All-In-One Desk Reference for Dummies, and Conversation Marketing. Follow him on Twitter at portentint, and on LinkedIn at LinkedIn.com/in/ianlurie.

Start call to action

See how Portent can help you own your piece of the web.

End call to action
0

Comments

  1. Whether Nerd Ian or Marketing Ian arrives in my inbox, I am always delighted to read your emails. Your sense of humor is wacky and wonderful. The knowledge you share very much appreciated.
    I especially liked yesterday’s giving points to clients or taking them away.
    All the best,
    Lois

Comments are closed.

Close Mobile Menu Button
Close search overlay