Created
May 28, 2014 10:40
-
-
Save yatharth/e1c7634946a46c266872 to your computer and use it in GitHub Desktop.
Google Sheets App Script for Multiple-column range-wide auto-sort
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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