I have the following code that I'm trying to link to a button to sort a range on the page by the column H (Date). I got the button linked but the code is not working
function sortRange() {
var ss = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('FBY Team');
var sheet = ss.getSheets()[0];
var range = sheet.getRange("A6:M100");
range.sort({column: 2, ascending: true});
}
I have added a link to my test spreadsheet. https://docs.google.com/spreadsheets/d/1iWQ40boplJcJmdFg9HNIyOAOrHOjlCRu362LWRdV5y0/edit?usp=sharing
The problems
'FBY Team' is not one of your sheet.ss variable for spreadsheets here you are trying to grab a sheet.Solution
what I suggest is you change your code to:
function sortRange() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheetByName('Your Sheet 1');
var range = sheet.getRange("A7:M100");
range.sort({column: 2, ascending: true});
}
this should work now.
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