I'm using the command =COUNTA(I31:I) to count all non-empty cells in the column. The cells in the column contain this line of code:

=IF(ISNUMBER(D31), "X", "")

The result is that the cells are either an empty string (the line with add nothing "") or contain an X.

The problem now is that COUNTA counts all the cells after this procedure, empty or not. If I delete the long command line the cell is not counted and it works fine. So this long command line is adding something to the cell, so it appears not-empty even though it looks empty.

Any clues to what that is? My guess is that I should use some kind of Null operator instead of the "" to add nothing to the cell.

Note: For some reason, this seems to work in a previous version of Google Spreadsheet I had.

As a potential workaround, I could replace =COUNTA(I31:I) by checking specifically for x with =COUNTIF(I31:I;"X"). But I'm still curious as to the problem with COUNTA.

If it turns out that my cells are not empty 'enough' for this command, how can I then make them completely empty?

See Also: Count rows with not empty value


Unfortunately, this is functions as designed from Google.
<sup>Although I'm not sure why it's divergent from the way that Excel calculates COUNTA.</sup>

According to the Google Spreadsheet Documentation on COUNTA:

COUNTA counts all values in a dataset, including those which appear more than once and text values (including zero-length strings and whitespace).

Meaning that the only way to "make [the cells] completely empty" is to delete the entire contents, formula and all. But fear not...

Some workarounds:

  1. Hypothetically, you should be able to do this with =COUNTIF(A3:A8,"<>"&""), but Google spreadsheets doesn't support the not equal to operator in the COUNTIF function according to these forums: 1, 2, 3

  2. A workaround is to create a truthy or falsy array based on the condition and use SUMPRODUCT to count the truthy values like this:

     =SUMPRODUCT((A3:A8<>"")*1)
    
  3. Another option you could pursue would be to write a custom function and add it to Drive.
    It's actually pretty easy to do so. Go to Tools > Script Editor and add the following script:

    <!-- language: lang-js -->
     /**
      * Works like COUNTA except does not include null strings
      *
      * @param {cellRange} myArray The value or range to consider when counting.
      * @return Returns the a count of the number of values in a dataset.
      * @customfunction
      */
     function CountNotBlank(myArray) {
       var output = 0;
       for (i = 0; i < myArray.length; i++) { 
         if (myArray[i] != "") {
           output += 1
         }
       }
       return output;
     }
    

    Then use like this:

     =CountNotBlank(I31:I)