class SpreadsheetApp method .getNumRows()

SpreadsheetApp is the Apps Script service.

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

What it does

Returns how many rows are in a range.

Why it's used

  • Loop the right number of times when processing a selected range.
  • Size arrays to match the range you are working on.

Common errors

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

Explore

Related methods

  • .getNumColumns()

    Returns how many columns are in a range.

  • .getMaxRows()

    Returns the total number of rows the sheet can hold.

  • .getRow()

    Returns the starting row index of a range.

  • .getRange()

    Returns a range of cells by A1 notation or row and column numbers.

  • .getLastRow()

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

Better Sheets tutorials

Count Merged Rows

Count Merged Rows

Count the number of cells or rows in a merged cell. This is a quick litt...
How to Merge Cells in Google Sheets

How to Merge Cells in Google Sheets

A master class on merging cells. How to merge two cells. How to merge mu...
How to Trigger Macros Daily

How to Trigger Macros Daily

Automate your apps script and macros you can record.
Reformat Pasted Cells Automatically

Reformat Pasted Cells Automatically

Create uniform formatting even if you're copy and pasting data that is d...

Related blog posts

Written guides about SpreadsheetApp.getNumRows().

Browse the blog