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

20,822

Solution 1

I was having this exact problem, and I just found out about the "?*" wildcard which searches for any one or more characters, thus avoiding the empty string problem--genius! See Jonathan Gawrych's answer (posted right after the selected answer) here:

Excel Countif Not equal to string length of zero

Not sure if this works for the OP, since it looks like the value in A1 could need to be handled as a number not a string, but it might help anyone else who arrived here looking for a text-parsing solution.

Solution 2

Is using SUM instead of COUNTIFS an option? If so, I've found it to be much more flexible for filtering data sets. For example:

=SUM(IF(NOT(ISBLANK(A1:A3)),IF(NOT(ISTEXT(A1:A3)),1,0),0))

(entered as an array formula). IF(NOT(ISBLANK(x))... filters out non-blanks, then IF(NOT(ISTEXT(x))... filters out non-text. Whatever survives the filters is counted by summing 1. You can add as many filters as necessary. If you wanted to filter out only empty strings but include other text entries you could use a filter like

IF(ISTEXT(x),IF(LEN(x)>0,1,0),0)

Share:
20,822
sancho.s ReinstateMonicaCellio
Author by

sancho.s ReinstateMonicaCellio

user245595 Part of the story about Monica Cellio. Parties in a dispute have usually better chance by talking to each other (not infallible, but worth a try). https://judaism.meta.stackexchange.com/questions/5193/stack-overflow-inc-sinat-chinam-and-the-goat-for-azazel

Updated on June 25, 2020

Comments

  • sancho.s ReinstateMonicaCellio
    sancho.s ReinstateMonicaCellio almost 4 years

    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.