Delete a row in Google Spreadsheets if value of cell in said row is 0 or blank

前端 未结 10 797
情书的邮戳
情书的邮戳 2020-11-29 02:01

I\'d like to be able to delete an entire row in a Google Spreadsheets if the value entered for say column \"C\" in that row is 0 or blank. Is there a simple script I could w

10条回答
  •  攒了一身酷
    2020-11-29 02:38

    reading your question carefully, I came up with this solution:

    function onOpen() {
      // get active spreadsheet
      var ss = SpreadsheetApp.getActiveSpreadsheet();
    
      // create menu
      var menu = [{name: "Evaluate Column C", functionName: "deleteRow"}];
    
      // add to menu
      ss.addMenu("Check", menu);
    }
    
    function deleteRow() {
      // get active spreadsheet
      var ss = SpreadsheetApp.getActiveSpreadsheet();
    
      // get active/selected row
      var activeRow = ss.getActiveRange().getRowIndex();
    
      // get content column C
      var columnC = ss.getRange("C"+activeRow).getValue();
    
      // evaluate whether content is blank or 0 (null)
      if (columnC == '' || columnC == 0) {
        ss.deleteRow(parseInt(activeRow));
      }
    }
    

    This script will create a menu upon file load and will enable you to delete a row, based on those criteria set in column C, or not.

提交回复
热议问题