How to run onEdit on multiple sheets

后端 未结 1 1384
独厮守ぢ
独厮守ぢ 2020-12-12 05:19

My code is a scheduler that makes a user sign-up to a particular slot in a particular sheet. The problem is that the code works only on the first sheet (\"Jan 20 Mon\").

相关标签:
1条回答
  • 2020-12-12 06:08

    Read Spreadsheet Edit Events in Understanding Events. Using the event that's delivered to an onEdit function, you can determine where an edit has occurred, and avoid using any explicit methods to retrieve that information.

    Caveat: This feature is currently broken with the New Sheets that was introduced Dec 2013. There are enough Scripting Issues that you should avoid using the New Sheets for now.

    This is an example of how you could do that.

    function onEdit(event) {
      var ss = event.source;  // you don't use this, but if you did, here's how to get it
    
      var cell = event.range;  // This is the cell that was edited
      // TODO: Add code that returns immediately if the edit occurred somewhere we don't care about
    
      var sheet = cell.getSheet();
    
      var request = sheet.getRange("B2:E2").getValues();
      var conditionas = request[0];
      var conditionbs = request[1];
      var conditioncs = request[2];
      var conditionds = request[3];
    
      if (conditioncs == "1" && conditionds == "None") {
        var response = Browser.msgBox("PLEASE RECHECK SCHEDULE AND TID.", conditionas+" , "+conditionbs+" Are you sure?", Browser.Buttons.YES_NO);
        if (response == "yes") {
          sheet.hideRows(2,1);
          sheet.getRange('E2').setValue("1");
          //insert msgBox here
        } else {
          Browser.msgBox("Input again.");
        }
      }
    }
    
    0 讨论(0)
提交回复
热议问题