简体   繁体   中英

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.

If I use this formula for conditional formatting, =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")). it just returns zero.

在此处输入图像描述

What am I missing?

You need to use COUNTIFS and separate the conditions.

=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. 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 will return a TRUE/FALSE and then the COUNTIF would look for that result in the Range. Since none of the cells are TRUE or FALSE it will return 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?)

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")

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