class SpreadsheetApp method .getLastColumn()

SpreadsheetApp is the Apps Script service.

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

What it does

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

Why it's used

  • Detect how wide a table is before looping across columns.
  • Know where to write the next new field without hardcoding column letters.

Common errors

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

Explore

Related methods

Better Sheets tutorials

No tagged tutorials yet. Fetch Apps Script from the harvest table and this page fills automatically.

Related blog posts

Written guides about SpreadsheetApp.getLastColumn().

Browse the blog