How to define a non continuous range in COUNTIF

China☆狼群 提交于 2019-11-27 03:14:17

问题


   A    B   C

1  Β        Β
2  Β        Β
3  Α        Α
4  Α        Α
5  Β        Β
6  Α        Α
7  Α        B
8  Β        Β
9  Β        Β
10 Α        Α
11 Β        A
12 Α        Α
13 Α        Α
14 Β        Β
15 Α        Α
16 Β    ??  

In cell B16 I want to count how many "B"s (the value in A16) are in cells C1:C15 and A16. Then using some function I will put an "A" or "B" in cell C16. How can I give such a range in COUNTIF? The same formula must be used for every cell in column B.


回答1:


Here's the formula for cell B16: =SUM(COUNTIF(INDIRECT({"C1:C15","A16"}),"B"))




回答2:


As an alternative that would work for copying and pasting, you could do:

=COUNTIF($C$1:$C$15,"B") + COUNTIF(A16,"B")



回答3:


For the record, if I understand well, you want to count the value from the cell A16. But if you do such a formula:

=COUNTIF(C1:C15,A16)

You know you will have the value (here B) in cell A16, don't you?

So the value you want to get is:

=COUNTIF(C1:C15,A16) + 1

What did I misunderstand?




回答4:


You can also declare a named range of non-contiguous ranges, but you must use the INDIRECT function in declaring the range. Otherwise, it will fail just like a normal, non-contiguous range.

Declaring the range ("Range1") should have the "applies to" field read:

=INDIRECT({"A1:B2","C4:F17"})

Or use other named ranges:

=INDIRECT({"Table1[Column1]","Table2[Column3]","Table4[Column2]")

Then you can reference it like:

=COUNTIF(Range1,"=Yes")



回答5:


This also worked! =SUM(COUNTIF(INDIRECT({"J18","J45","J78","J112","J140","J173","J205"}),">1"))



来源:https://stackoverflow.com/questions/8421139/how-to-define-a-non-continuous-range-in-countif

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!