Have COUNTIFS ignore all blank cells (= empty cells and cells containing "")

sancho.s ReinstateMonicaCellio picture sancho.s ReinstateMonicaCellio · Mar 27, 2015 · Viewed 17.7k times · Source

I want to get a formula with COUNTIFS, like

=COUNTIF(A1:A3,"<>"&"")

such that when A1 = 2, A2 = "", A3 = empty, it returns 1.

Notes:

  1. A2 contains an empty string, as the result of a formula. A3 is a blank cell, with no formulas in it.
  2. The formula posted returns 2.
  3. I tried using various numbers of double quotes. I always get 2.
  4. I tried using &CHAR(34)&CHAR(34). I get 2.
  5. The solution posted in How do I get countifs to select all non-blank cells in Excel? is what I tried, it returns 2 (not useful).
  6. The formula would actually be =COUNTIFS(range1,cond1,range2,cond2), that is why I cannot use something like =ROWS(A1:A3)-COUNTIF(A1:A3,"") or =ROWS(A1:A3)-COUNTBLANK(A1:A3) (see this). range1 and range2 would come from expressions with INDIRECT, but that is probably not relevant.
  7. I have worked it out with =SUMPRODUCT(--(expression1),--(ISNUMBER(A1:A3))), but I am specifically asking about the possibility of using COUNTIFS. Discrimination of number vs. text (e.g.) is not relevant at this point.
  8. Blank vs. Empty string is the source of "troubles" (see, e.g., this).
  9. Excel itself is somewhat ambiguous with respect to the definition of BLANK. In my example, ISBLANK(A2) returns FALSE, but COUNTBLANK(A2) returns 1.
  10. I am not interested in a user Function.

Answer

user4039065 picture user4039065 · Mar 27, 2015

Use a SUMPRODUCT function that counts the SIGN function of the LEN function of the cell contents.

    COUNTIF against zero length strings

As per your sample data, A1 has a value, A2 is a zero length string returned by a formula and A3 is truly blank.

The formula in C2 is,

=SUMPRODUCT(SIGN(LEN(A1:A3)))