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.
5 Snippets using this methods
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
5 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
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 →