I'd like to sort range in sheetN2 if data in sheetN1 are changed, but the script doesn't work. Could anyone tell me where the problem is?

function onEdit(event){
    var ss = event.getActiveSpreadsheet(); 
    var sheet = ss.getSheetByName("sheetN1"); 
    var editedCell = sheet.getActiveCell();

    var sheet2 = ss.getSheetByName("sheetN2"); 
    var columnToSortBy = 1;
    var tableRange = "A4:E1100";

    if(editedCell.getColumn() == columnToSortBy){   
    var range = sheet2.getRange(tableRange);
    range.sort([{column: 3, ascending: true}, {column: 2, ascending: true}]);
  • I think that providing the detail information about the script doesn't work will help users think of your solution. – Tanaike Apr 4 at 23:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.