简体   繁体   中英

Excel Formula CountIFS with any digit

I can't get COUNTIFS to work with searching for any digit.

This works for if I make the second criteria a specific numerical value

=COUNTIFS(FOO!B:B,"*foobar*",FOO!C:C,"2")

but I don't just want to search for 2 , I want any numerical value (or even any string containing a digit). I tried a few variations, but from what I understand this should work below. What am I missing?

=COUNTIFS(FOO!B:B,"*foobar*",FOO!C:C,"*{1,2,3,4,5,6,7,8,9,0}*")

Data

A     B         C
      foobar    51
      foo       682
      bar       S5
      foobar    CSGR
      foobar    8RD

The countifs formula should return 2 given I want where column B is foobar and column C contains any digit.

You can use something like =COUNT(FIND({0,1,2,3,4,5,6,7,8,9}),C2)>0 for column C and copy down in column D. This will return TRUE or FALSE if there is a digit in the cell.

then do something along the lines of =COUNTIFS(FOO!B:B, "*foobar*", FOO!D:D, TRUE)

This has not been tested.

Ok...

This is a bit long winded and there might be a better way but it works without a helper column:

在此处输入图片说明

=SUMPRODUCT(
    --NOT(ISERROR(SEARCH("*foobar*",B1:B5)))*
    (
        (
            --NOT(ISERROR(SEARCH("*0*",C1:C5)))+
            --NOT(ISERROR(SEARCH("*1*",C1:C5)))+
            --NOT(ISERROR(SEARCH("*2*",C1:C5)))+
            --NOT(ISERROR(SEARCH("*3*",C1:C5)))+
            --NOT(ISERROR(SEARCH("*4*",C1:C5)))+
            --NOT(ISERROR(SEARCH("*5*",C1:C5)))+
            --NOT(ISERROR(SEARCH("*6*",C1:C5)))+
            --NOT(ISERROR(SEARCH("*7*",C1:C5)))+
            --NOT(ISERROR(SEARCH("*8*",C1:C5)))+
            --NOT(ISERROR(SEARCH("*9*",C1:C5)))
        )>0
    )
)

If the SEARCH function returns an error, it means that the text was not found. The result of the SEARCH function is converted into a 0 or a 1 by the --NOT(ISERROR( parts.

So for each row, we are checking if column B contains "foobar". If so, it returns a 1. This is then multiplied by the result of the second half of the formula (also a 0 or a 1). In the second half, we are adding up how many checks for digits do not result in an error. If this number is greater than 0 (ie at least one digit was found), it returns 1. If no digits were found, a 0 is returned.

This results a sum of 1*1, 1*0, 0*1, or 0*0. This means that the sum for each row only results in a 1 if the text is found in BOTH columns, otherwise, it returns 0.

The SUMPRODUCT then simply adds up these zeros and ones to give the total number of rows which satisfy your criteria.

I hope that makes sense. If you need any more explanation, just let me know.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM