Returns the row number of the last row that has content.
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
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.
Snippets using this method
- Spreadsheet Automation for Beginners
- Tag Emails From A List of Members in Google Sheets
- Twitter App Clone in a Google Sheet
- Send a Daily Email with Inspiring Quote - A Little Pick Me Up
- Track Every Edit (Almost)
- Sheet Stories / Video Notes + Clear 24 Hour Old Videos
- Introducing SheetFools
- Move Blank Rows
- Move Entire Row when a Cell is changed to "Yes" - The $75,000 Google Script
- LinkTree in a Google Sheet
- How To Format Sheets for Notes
- How to Format Timestamp to Day and Month
- How to Power Testimonials with Google Forms and Sheets
- Google Maps Scraper for Outreach
- How To Change Date Format Automatically
- How to Copy To New Tab When Checked
- Hold a Giveaway Raffle in a Google Sheet
- Dylan Asks: How to Automatically Delete Rows If Cell Contains Value
- Google Sheets Stories? No! But we'll add timestamped video notes to your google sheets.
- Create a PR Agency From Scratch
- Better Sheets Videos Checklist
- Build a License Key Generator and API in 20 Minutes
- Build a Job Status Checker API in 15 Minutes
- Basic CRM - Add a Powerful Script To Move Row Based on Status
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.
More Apps Script
Better Sheets tutorials
Add Click Tracking To Your Google Sheets | Bitly in a Google Sheet
Add NPS to Your Google Site
Automate Google Sheets With Zero Experience
Automate Move Blank Rows
Basic CRM - Add a Powerful Script To Move Row Based on Status
Build a License Key Generator and API in 20 Minutes
Create a PR Agency From Scratch
Dylan Asks: How to Automatically Delete Rows If Cell Contains Value
Google Maps Scraper for Outreach
Google Sheets Stories? No! But we'll add timestamped video notes to your google sheets.
Hold a Giveaway Raffle in a Google Sheet
How To Change Date Format Automatically
How to Copy To New Tab When Checked
How To Format Sheets for Notes
How to Format Timestamp to Day and Month
Introducing SheetFools
LinkTree in a Google Sheet
Move Blank Rows
Move Entire Row when a Cell is changed to "Yes" - The $75,000 Google Script
Send a Daily Email with Inspiring Quote - A Little Pick Me Up
Tag Emails From A List of Members in Google Sheets
Track Every Edit (Almost)
Related blog posts
Written guides about SpreadsheetApp.getLastRow().
Automate Row Deletion in Google Sheets with Apps Script
In this post, we'll cover how to remove rows automatically in Google Sheets using Apps Script, ensuring you save time and streamline your spreadsheet management. You're probably already familiar with the manual way of right-clicking and deleting rows, but there's a more efficient way to handle this—automation! Manual versus Semi-Automatic Deletion You may know that you can manually delete rows in Google Sheets by right-clicking and selecting "Delete row." You can even select multiple rows...
Read post →What's Better Than Google Sheets?
Nothing is better than Google Sheets. You just need to learn more about the unlimited power of Google Sheets. Functions, Formulas, Apps Script and more.
Read post →How to reference a different Google Spreadsheet in Apps Script?
Transferring Data Between Cells in Different Spreadsheets
Read post →