简体   繁体   English

具有任何数字的Excel公式CountIFS

[英]Excel Formula CountIFS with any digit

I can't get COUNTIFS to work with searching for any digit. 我无法让COUNTIFS搜索任何数字。

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). 但是我不只是想要搜索2 ,我想要任何数值(甚至任何包含数字的字符串)。 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. 给定我想要的值,countifs公式应返回2 ,其中B列是foobar ,C列包含任何数字。

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. 您可以对C列使用=COUNT(FIND({0,1,2,3,4,5,6,7,8,9}),C2)>0 ,然后在D列中向下复制。这将返回如果单元格中有数字,则为TRUE或FALSE。

then do something along the lines of =COUNTIFS(FOO!B:B, "*foobar*", FOO!D:D, TRUE) 然后按照=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. 如果SEARCH函数返回错误,则表示未找到文本。 The result of the SEARCH function is converted into a 0 or a 1 by the --NOT(ISERROR( parts. SEARCH函数的结果由--NOT(ISERROR(部件)转换为0或1。

So for each row, we are checking if column B contains "foobar". 因此,对于每一行,我们正在检查B列是否包含“ 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). 如果是这样,它将返回1。然后将其乘以公式后半部分的结果(也为0或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. 如果该数字大于0(即找到至少一位数字),则返回1。如果未找到数字,则返回0。

This results a sum of 1*1, 1*0, 0*1, or 0*0. 结果为1 * 1、1 * 0、0 * 1或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. 这意味着,如果在BOTH列中都找到了文本,则每一行的总和只会得到1,否则返回0。

The SUMPRODUCT then simply adds up these zeros and ones to give the total number of rows which satisfy your criteria. 然后,SUMPRODUCT只需将这些零和一加起来即可得出满足您条件的总行数。

I hope that makes sense. 我希望这是有道理的。 If you need any more explanation, just let me know. 如果您需要更多说明,请告诉我。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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