Take the 2-minute tour ×
Web Applications Stack Exchange is a question and answer site for power users of web applications. It's 100% free, no registration required.

In a Google Spreadsheet I have different group of cells to auto-sort ascending i.e.

  • table range a3:c16 columntosortby = 2
  • table range d18:f31 columntosortby = 5
  • table range g33:i46 columntosortby = 8

etc.

By using the following code I'm able to auto-sort the first group:

/**
* Automaticamente ordina arrivi gruppo A 
*/

function onEdit(event){
  var sheet = event.source.getActiveSheet();
  var editedCell = sheet.getActiveCell();

  var columnToSortBy = 2;
  var tableRange = "a3:c16"; // Celle da ordinare.

  if(editedCell.getColumn() == columnToSortBy){   
    var range = sheet.getRange(tableRange);
    range.sort( { column : columnToSortBy, ascending: true } );
  }
}

If I replicate one script for each of others groups only the last script remains active. How can I solve this?

share|improve this question

1 Answer 1

I've got a solution by creating three different scripts:

  1. auto-sorting table range a3:c16 columntosortby = 2 ;
  2. auto-sorting table range a3:c16 columntosortby = 2 and auto-sorting table range d18:f31 columntosortby = 5;
  3. auto-sorting table range a3:c16 columntosortby = 2 + auto-sorting table range d18:f31 columntosortby = 5 + table range g33:i46 columntosortby = 8

Doesn't seems very elegant to me but it functions.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.