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

后端 未结 3 418
终归单人心
终归单人心 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条回答
  •  旧时难觅i
    2021-01-26 11:03

    Use TextFinder class.

    Sample script:

    /**
     * @customfunction
     * @return count of given text in spreadsheet
     * @param {string} text text to search
     * @param {boolean} mec whether to match entire cell
     * @param {boolean} mc whether to match case
     */
    function COUNT_SS(text = 'NOT COMPLETE', mec = true, mc = true) {
      return SpreadsheetApp.getActive()
        .createTextFinder(text)
        .matchEntireCell(mec)
        .matchCase(mc)
        .findAll()
        .length;
    }
    

    Usage:

    =COUNT_SS()
    

提交回复
热议问题