To automatically sort data in Google Sheets you can use this Apps Script.  The video above takes you through the steps or you can follow the notes below.

function onEdit(event){
  var w = event.source.getSheetByName("Scores");//Replace Scores with the name of the worksheet you want to sort in
  var c = w.getActiveCell();

  var srtby = 2; //Change this to the position of the col you want to sort by
  var t = "A2:B"; // Change this to range of cells that you want to sort (don't include the column headings).

  if(c.getColumn() == srtby){   
    var range = w.getRange(t);
    range.sort( { column : srtby, ascending: false } );//change false to true if you want to sort in ascending order
  }
}

Installing the Script

  1. Copy the script above
  2. Open the Google Sheets file you want to use the script in
  3. Click on the Extensions menu and select Apps Script
  4. Select any existing script in the script window and paste my script over it to replace it
  5. Give the Project a name (top of screen)
  6. Save the Project (look for save button near the top)
  7. You can then close down that tab in your browser

Amending the Script

You will need to make some changes to the script so that it works for your data:

Line 2 change the word Scores to the sheet name that you want to sort in

Line 5 change the number to the position of the column within your data that you want to sort on

Line 6 change the range A2:B to reflect the range of cells that your data resides in

Line 10 change the word false to true if you want to sort in ascending order

 

Comments

  1. Chris Godby

    I’m using this, but want to apply the sorting to 5 sheets (tabs) in the same project. Do i somehow apply the script 5 times, or is there a way to list multiple sheets on line 2 of the script? I am new at using Apps Scripts. Thanks.

  2. Luis Villalobos

    THANK YOU!
    i have been scouring the web looking for this solution. After trying all the others, yours ACTUALLY worked.

    Huge THANKS

Leave a Reply

Your email address will not be published. Required fields are marked *