0
votes

I have a function OnEdit Script running that used to auto sort on edit column 3 that is no longer working when edited; I have to go in and run it manually to get it to sort. It works in another google sheets file I have. Can someone please help?

My script and file links are below:

https://docs.google.com/spreadsheets/d/1DcLsFpVn90hCg0biVa_zyjKz2GdEmlqui0a3oF0ZQW8/edit?usp=sharing

function OnEdit() {
  var sheetNames = ["ALPHA"];

  var ss = SpreadsheetApp.getActiveSpreadsheet();
  sheetNames.forEach(function(name) {
    var sheet = ss.getSheetByName(name);
    var range = sheet.getRange(2, 1, sheet.getLastRow() - 1, sheet.getLastColumn());
    range.sort([{column: 3, ascending: true}])
  });
}
2
If the trigger is manually installed, delete the trigger, close the dialog box and then install the trigger again. Unfortunately, triggers have a history of silently failing for no known reason.Alan Wells

2 Answers

1
votes

Replace your current script with

function onEdit(e) {
var sh = e.source.getActiveSheet();
if (sh.getName() !== 'ALPHA') return;
sh.getRange(2, 1, sh.getLastRow() - 1, sh.getLastColumn()).sort(3)
}

Then go back to your spreadsheet and edit the sheet ALPHA and see if the sorting takes place.

0
votes

In the script editor, change 'OnEdit' to 'onEdit' and it should be fine.