1

I have the following script adapted from a source online that works great on one sheet. How could I adapt it to also run on the sheets 'Year 2' and 'Year 3'?

The adjacent tabs: 'Year 2' and 'Year 3' have identical layouts columns and row information so this doesn't need to be adjusted for in any iterations.

SHEET_NAME = "Year 1";
SORT_DATA_RANGE = "A5:CD999";
SORT_ORDER = [
{column: 2, descending: false},  // 2 = column number, sorting by descending order
{column: 1, ascending: true}, // 1 = column number, sort by ascending order 
];

function onEdit(e){
  multiSortColumns();
}
function multiSortColumns(){
  var ss = SpreadsheetApp.getActiveSpreadsheet();
  var sheet = ss.getSheetByName(SHEET_NAME);
  var range = sheet.getRange(SORT_DATA_RANGE);
  range.sort(SORT_ORDER);
  ss.toast('Sort complete.');
}
0

0

Browse other questions tagged or ask your own question.