I have been looking for a way to script an auto-sort on a Google Sheet that does the following:
- Only applies to a specific range (A35:I911), but on all of the worksheets within the main Google Sheet.
- Sorts the A column (Date of Post) first and the B column (Time of Post) second.
- Occurs on edit of any cell within that range (A35:I911).
I tried the following code, but it will not work properly:
function onEdit(event) {
var postDate = 1;
var postTime = 2;
var sheet = event.source.getActiveSheet();
var tableRange = "A35:I911";
var range = sheet.getRange(tableRange);
range.sort([
{column: postDate, ascending: true},
{column: postTime, ascending: true}
]);
}
Thank you in advance!
Here is a link to a redacted version of the Google Sheet: https://docs.google.com/spreadsheets/d/1NUy6aY-lEA66UFXg4Yx4mXsTgFvj5g2Dhv4jToYsQnw/edit?usp=sharing)