Search code examples
google-sheetscountgoogle-sheets-formulaarray-formulasis-empty

Create serial count in column if adjacent cell is blank (Google Sheets)


I'm trying to create a simple counting ArrayFormula that iterates by one, if adjacent cell is empty (doesn't contain "IGNORE"). E.g. COUNT column here should only count when STATUS <> IGNORE:

ROW   STATUS    COUNT
______________________
1     IGNORE    
2     IGNORE
3                 1
4                 2
5                 3
6     IGNORE
7     IGNORE
8                 4
9                 5

What ArrayFormula can I use here in cell C1 COUNT?


Solution

  • You can create a custom function and integrate it with ARRAYFORMULA.

    Example

    Code:

    function countNonIgnore(values) {
      var tempArr = [];
      var ctr = 1;
      values.forEach(val => {
        if(val[0] == "IGNORE"){
          tempArr.push([""]);
        }else{
          tempArr.push([ctr]);
          ctr++;
        }
      })
      return tempArr;
    }
    

    Output:

    enter image description here

    Reference: