Skip to content

Instantly share code, notes, and snippets.

@yatharth
Created May 28, 2014 10:40
Show Gist options
  • Save yatharth/e1c7634946a46c266872 to your computer and use it in GitHub Desktop.
Save yatharth/e1c7634946a46c266872 to your computer and use it in GitHub Desktop.
Google Sheets App Script for Multiple-column range-wide auto-sort
function onEdit(event) {
var sheet = SpreadsheetApp.getActiveSheet();
var editedCell = sheet.getActiveCell();
var rangeValue = "A2:D";
var columns = [3, 2, 1];
var ascendings = [true, false, true];
if (editedCell.getColumn() in columns) {
var range = sheet.getRange(rangeValue);
var args = columns.map(function(elem, index) {
return {column: elem, ascending: ascendings[index]};
});
range.sort(args);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment