Ross Symonds
Ross Symonds

Reputation: 81

Find Last Row in Google Sheets

I am finding the macro element of Google Sheets considerably more difficult than VBA. I want to try and calculate the last occupied row. And then I wanted to be shown a message with the value of lr. In VBA, I could have done this in minutes.

function Test() {
  var ss = Spreadsheetapp.getactivespreadsheet().getActiveSheet();
  var lr = ss.getLastRow();
  Browser.msgBox(lastRow);
}

I am getting the error message ReferenceError: Spreadsheetapp is not defined which I don't really understand. I have seen some other posts about this issue on StackOverflow but failed to understand the answers provided.

Update

After Andi commented below I had another look and changed my code to var ss = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();. And now it works.

Upvotes: 0

Views: 234

Answers (1)

Andi Nuruljihad
Andi Nuruljihad

Reputation: 88

Simple solution, man. It's SpreadsheetApp, not spreadsheetapp. Capitalize the A.

It's giving you that error because the script is looking for a variable named Spreadsheetapp, which doesn't exist.

Also, it's getActiveSpreadsheet() and not getactivespreadsheet() for the same reason as above.

https://developers.google.com/apps-script/reference/spreadsheet/spreadsheet-app

Upvotes: 2

Related Questions