Returns the smallest range that contains all data on the sheet.
class SpreadsheetApp method .getDataRange()
SpreadsheetApp is the Apps Script service.
.getDataRange() is the method name you will see after a dot in your code.
What it does
Why it's used
- Grab everything on a sheet without guessing the last row.
- Export or process a full table in one shot.
Common errors
- Forgetting parentheses on getDataRange. Write SpreadsheetApp.getDataRange(), not SpreadsheetApp.getDataRange or getDataRange by itself.
- Skipping dots between chained calls. Each step needs a dot, like SpreadsheetApp.getActiveSpreadsheet().getSheetByName('Data').getDataRange().
- Adding spaces where they do not belong. Write SpreadsheetApp.getDataRange(), not SpreadsheetApp .getDataRange(), SpreadsheetApp.getDataRange (), or SpreadsheetApp . getDataRange().
- Wrong capitalization. Use SpreadsheetApp and getDataRange, not spreadsheetapp or getdatarange.
Snippets using this method
Explore
Related methods
-
.getRange()
Returns a range of cells by A1 notation or row and column numbers.
-
.getActive()
Returns the range the user currently has selected.
-
.getRow()
Returns the starting row index of a range.
-
.activate()
Makes a sheet or range the active selection.
-
.getValues()
Reads values from every cell in a range as a 2D array.
More Apps Script
Better Sheets tutorials
Brighten Up Your Checklist Automatically
I Created an Automatic Emailer
Related blog posts
Written guides about SpreadsheetApp.getDataRange().
How to reference a different Google Spreadsheet in Apps Script?
Transferring Data Between Cells in Different Spreadsheets
Read post →Spreadsheets Explained! 5 Levels of Difficulty: From Basic Text Input to Google Apps Script
Five increasingly difficult ways of explaining spreadsheets in Google Sheets: The basics of Google Sheets text Menu items in Google Sheets Math inside Google Sheets Using Formulas in Google Sheets Apps Script in Google Sheets
Read post →How to Change Border Colors in Google Sheets with Apps Script
Recolor only the borders you already have in Google Sheets, with a hex code prompt, a reset button, and a custom menu. The real Apps Script from Big Year Premium, explained step by step.
Read post →