简体   繁体   English

Excel:公式适用于条件格式,但似乎不适用于单元格

[英]Excel: Formula works in conditional formatting, but does not seem to in cell

I would like to count up the number of cells that have specific values in the same cell on different sheets.我想计算不同工作表上同一单元格中具有特定值的单元格的数量。 For example, I want to count if Sheet1,A1="TEST" and Sheet2.A2="NO", I want to count it.比如我要统计如果Sheet1,A1="TEST" and Sheet2.A2="NO",我要统计。

If I use this formula for conditional formatting, =AND(Sheet2,A1="NO", A1<>"NAME").如果我将此公式用于条件格式,=AND(Sheet2,A1="NO", A1<>"NAME")。 it works great.它很好用。

在此处输入图像描述

But if I try and use it as a condition to count the number of cells that meet that same criteria, =COUNTIF(A1:A4,AND(Sheet2,A1="NO", A1<>"NAME")).但是,如果我尝试将其用作计算满足相同条件的单元格数量的条件,=COUNTIF(A1:A4,AND(Sheet2,A1="NO", A1<>"NAME"))。 it just returns zero.它只是返回零。

在此处输入图像描述

What am I missing?我错过了什么?

You need to use COUNTIFS and separate the conditions.您需要使用 COUNTIFS 并将条件分开。

=COUNTIFS(Sheet2!A1:A4,"No",A1:A4,"<>NAME")

Or要么

=SUMPRODUCT((Sheet2!A1:A4="No")*(A1:A4<>"NAME"))

To explain why it failed.解释失败的原因。

First Conditional Format automatically iterates the Apply to Range changing the relative references as needed. First Conditional Format 自动迭代 Apply to Range 根据需要更改相对引用。 So referring to one cell in conditional formatting works but not in the formula as it will not iterate.因此,在条件格式中引用一个单元格有效,但在公式中无效,因为它不会重复。

Next using the AND as the criteria.接下来使用 AND 作为条件。 AND will return a TRUE/FALSE and then the COUNTIF would look for that result in the Range. AND 将返回 TRUE/FALSE,然后 COUNTIF 将在 Range 中查找该结果。 Since none of the cells are TRUE or FALSE it will return 0 .由于没有任何单元格是 TRUE 或 FALSE,因此它将返回0


But my guess is that this is not the real question you have.但我的猜测是,这不是你真正的问题。 That question is: "Why is the cell A2 not filled with conditional formatting?)这个问题是:“为什么单元格 A2 没有填充条件格式?)

See above about relative references and iterating.参见上面关于相对引用和迭代的内容。

I believe you want the following formula in your conditional formatting:我相信您希望在条件格式中使用以下公式:

=AND(Sheet2!$A$1="NO", A1<>"NAME")

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

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