I'm relatively new to scripting in google sheets and am trying to write something that can be assigned to a button to sort a table by column 5 in that table. I am using the code below:
function sort() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheetByName("items");
var range = sheet.getRange("J2:O13");
range.sort(5);
}
However, when I assign it to a button and click the button, I get the error message "Cell reference out of range". This may be a stupid question but thanks for any help in advance.
The SORTBY Function is not available in Google Sheets, but its SORT Function can be used instead and is more powerful than the SORT Function in Excel. It allows us to use multiple columns to dynamically sort data ranges.
Seems like you are trying to sort on col 5 (E) but that is not in your range. The first column in your range is col 10 (J). If you want to sort on col O you'll need
range.sort(15)
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