I have been using this script for sorting and so I know it works. Now I'm trying to use it on a new Google Sheet project. Except that the column I want to sort the entire sheet by isn't just one column but a merge, which I derived by merging columns 3 to 6. How do I modify my script to sort by the derived column? Here is my script:
function onEdit(event){
var sheet = event.source.getActiveSheet();
var editedCell = sheet.getActiveCell();
var columnToSortBy = 3; // doing 3:6 doesn't work
var tableRange = "A11:R82";
if(editedCell.getColumn() == columnToSortBy){
var range = sheet.getRange(tableRange);
range.sort( { column : columnToSortBy } );
}
}
After some trials and error, I did the following, but it's still not working:
function onEdit(event){
var sheet = event.source.getActiveSheet();
var editedCell = sheet.getActiveCell();
var columnToSortBy = [3,4,5,6];
var tableRange = "A11:R82";
if(columnToSortBy.includes(editedCell.getColumn()) ){
var range = sheet.getRange(tableRange);
range.sort( { column : columnToSortBy[0] }, { column : columnToSortBy[1] },{ column : columnToSortBy[2] },{ column : columnToSortBy[3] } );
}
}