function sortResponses() {
var Sheets = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Fall 01")
sheet.sort(3, false);
}
I have a Sheet called Fall 01
in my google Sheets, where I explicítly had to give the script access to, but it won't open, what am I missing?
The issue is that you have a standalone script which therefore is not bound to a google spreadsheet and as a result SpreadsheetApp.getActiveSpreadsheet()
returns null
.
There are two ways you can follow:
Solution 1:
Use SpreadsheetApp.openById(id) or SpreadsheetApp.openByUrl(url):
var Sheets = SpreadsheetApp.openById("Put your Spreadsheet ID").getSheetByName("Fall 01");
or
var Sheets = SpreadsheetApp.openByUrl("Put your Spreadsheet URL").getSheetByName("Fall 01");
Solution 2:
Go to the spreadsheet file that you want to work with and click on Tools => Script editor
on the top menu of the spreadsheet file and put your current code there.
Please Note
If this is your only code, sheet
is not defined, therefore you will get another error down the road. You most likely want to replace sheet
with Sheets
or the other way around. Be careful with this.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With