I am fairly new to Javascript/Apps Script.
I have a sheet that contains a few categories and their data on a single sheet. I am trying to create a script that sorts whats under each category (header) by column AP.
Currently we are manually selecting the range then running the following macro to sort by the column.
function SortAP() {
var spreadsheet = SpreadsheetApp.getActive();
spreadsheet.getActiveRange()
.sort({column: 42, ascending: true});
};
I want to have this query a row for a header and then run the function. Is this possible?
function sortEachColumn() {
const ss = SpreadsheetApp.getActive();
const sh = ss.getSheetByName('Sheet1');//Edit sheet name as necessary
const sr = 2;//data start row
[...Array.from(new Array(sh.getLastColumn()).keys(),x => sh.getRange(2,x+1,sh.getLastRow()).sort({column:x + 1,ascending:true}))];
}