How to count the number of cells which contain specific text using Google Sheet Scripts?

后端 未结 3 465
终归单人心
终归单人心 2021-01-26 10:37

How to count the number of cells which contain specific text using Google sheet scripts?

Currently I\'am using the following script to count the number of cells which co

3条回答
  •  感动是毒
    2021-01-26 11:22

    How about this:

    function COUNT_TEXT_ACROSS_SHEETS(sheetNames, range, text) {//text=['Complete','Not Complete']
      var nA=sheetNames.split(',');
      var tA=text.split(',');
      var count = 0;
      var cObj={};
      cObj[tA[0]]=0;
      cObj[tA[1]]=0;
      nA.forEach(function(name) {
        var sh=SpreadsheetApp.getActive().getSheetByName(name);
        var vA = sheet.getRange(range).getValues();
        vA.forEach(function(r) {
          r.forEach(function(c) {
            var idx0=c.indexOf(tA[0]);
            var idx1=c.indexOf(tA[1]);
            if(idx0!=-1 && idx1==-1)cObj[tA[0]]+=1;
            if(idx0!=-1 && idx1!=-1)cObj[tA[1]]+=1  
          });
        });
      });
      return Utilities.formatString('Count-%s:%s Count-%s:%s',tA[0],cObj[tA[0]],tA[1],cObj[tA[1]]);
    };
    

提交回复
热议问题