Need to delete an entire row based on one cell's criteria

后端 未结 1 1036
孤城傲影
孤城傲影 2021-01-16 04:09

In Google Sheets, I am trying to delete an entire row when one cell in that row contains the phrase \"Delivered.\" The onEdit function won\'t work for my needs because it re

相关标签:
1条回答
  • 2021-01-16 04:27

    Try this:

    function createTimeBasedTriggerIfYouDontAlreadyHaveOne() {
      if(!isTrigger(deleteDeliveredRows)) {
         ScriptApp.newTrigger(deleteDeliveredRows).timeBased().everyDays(1).atHour(0).create();
      }
    }
    
    function deleteDeliveredRows() {
      var ss=SpreadsheetApp.openById('ssid')
      var sh=ss.getSheetByName('sheetname');
      var rowStart=2;//assume 1 row for headers
      var rg=sh.getRange(rowStart,1,sh.getLastRow()-rowStart+1,sh.getLastColumn());
      var vA=rg.getValues();
      var d=0;
      for(var i=0;i<vA.length;i++) {
        if(vA[i][8]=="Delivered") {
          sh.deleteRow(i + rowStart - d++);
        }
      }
    }
    
    function isTrigger(funcName){
      var r=false;
      if(funcName){
        var allTriggers=ScriptApp.getProjectTriggers();
        for(var i=0;i<allTriggers.length;i++){
          if(funcName==allTriggers[i].getHandlerFunction()){
            r=true;
            break;
          }
        }
      }
      return r;
    }
    
    0 讨论(0)
提交回复
热议问题