Company logo
  • Jobs
  • Bootcamp
  • About Us
  • For professionals
    • Home
    • Jobs
    • Courses
    • Questions
    • Teachers
    • Bootcamp
  • For business
    • Home
    • Our process
    • Plans
    • Assessments
    • Payroll
    • Blog
    • Calculator

0

63
Views
Google sheets Script - Sort sheet by column AP under category headers (colored background)

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?

Here is an example sheet of what our headers look like

7 months ago · Juan Pablo Isaza
1 answers
Answer question

0

Sort Each Column

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}))];
}

enter image description here

Array.from()

7 months ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post job Plans Our process Sales
Legal
Terms and conditions Privacy policy
© 2023 PeakU Inc. All Rights Reserved.