Company logo
  • Empleos
  • Bootcamp
  • Acerca de nosotros
  • Para profesionales
    • Inicio
    • Empleos
    • Cursos y retos
    • Preguntas
    • Profesores
    • Bootcamp
  • Para empresas
    • Inicio
    • Nuestro proceso
    • Planes
    • Pruebas
    • Nómina
    • Blog
    • Calculadora

0

64
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos