class SpreadsheetApp method .getLastRow()

SpreadsheetApp is the Apps Script service.

.getLastRow() is the method name you will see after a dot in your code.

What it does

Returns the row number of the last row that has content.

Why it's used

  • Find where the data ends so you append on the next empty line.
  • Avoid overwriting rows when new records come in daily.

Common errors

  • Forgetting parentheses on getLastRow. Write SpreadsheetApp.getLastRow(), not SpreadsheetApp.getLastRow or getLastRow by itself.
  • Skipping dots between chained calls. Each step needs a dot, like SpreadsheetApp.getActiveSpreadsheet().getSheetByName('Data').getLastRow().
  • Adding spaces where they do not belong. Write SpreadsheetApp.getLastRow(), not SpreadsheetApp .getLastRow(), SpreadsheetApp.getLastRow (), or SpreadsheetApp . getLastRow().
  • Wrong capitalization. Use SpreadsheetApp and getLastRow, not spreadsheetapp or getlastrow.

Explore

Related methods

  • .getLastColumn()

    Returns the column number of the last column that has content.

  • .getMaxRows()

    Returns the total number of rows the sheet can hold.

  • .getRow()

    Returns the starting row index of a range.

  • .getNumRows()

    Returns how many rows are in a range.

  • .appendRow()

    Adds a new row of data at the bottom of the sheet.

5 Better Sheets tutorials

Add Click Tracking To Your Google Sheets | Bitly in a Google Sheet

Add Click Tracking To Your Google Sheets | Bitly in a Google Sheet

Create a click Edit: Google changed how the redirect is handled. It no l...
Add NPS to Your Google Site

Add NPS to Your Google Site

Create buttons on your Google Site to get an NPS, or Net Promoter Score ...
Automate Google Sheets With Zero Experience

Automate Google Sheets With Zero Experience

By the end of this video you should be knowledgeable about how to automa...
Automate Move Blank Rows

Automate Move Blank Rows

Automate the apps script we just created that moves blank rows from one ...
Basic CRM - Add a Powerful Script To Move Row Based on Status

Basic CRM - Add a Powerful Script To Move Row Based on Status

we're going to be adding a very powerful script to our CRMs or any datab...

Related blog posts

Written guides about SpreadsheetApp.getLastRow().

Browse the blog