Conditional Format based on a range

TTP

New Member
Joined
Jun 2, 2023
Messages
10
Office Version
  1. 2021
Platform
  1. Windows
Please help to conditional format cell A1 --> all cells in a column D (range) need to have the same answer e.g. either ALL need to be YES to be green in A1 or NO to be red.

Formula needs to be based on a range of cells
 

Excel Facts

Excel motto
Not everything I do at work revolves around Excel. Only the fun parts.
You should simply be able to use a COUNTIF function in your Conditional Formatting formula, i.e.
Excel Formula:
=OR(COUNTIF(D1:D7,"Yes")=7,COUNTIF(D1:D7,"No")=7)
 
Upvote 0
try this:
Book1
ABCD
1yes
2yes
3yes
4YES
Sheet4
Cells with Conditional Formatting
CellConditionCell FormatStop If True
A1Expression=COUNTIF($D$1:$D$4,"NO")=COUNTA($D$1:$D$4)textNO
A1Expression=COUNTIF($D$1:$D$4,"YES")=COUNTA($D$1:$D$4)textNO
 
Upvote 0
try this:
Book1
ABCD
1yes
2yes
3yes
4YES
Sheet4
Cells with Conditional Formatting
CellConditionCell FormatStop If True
A1Expression=COUNTIF($D$1:$D$4,"NO")=COUNTA($D$1:$D$4)textNO
A1Expression=COUNTIF($D$1:$D$4,"YES")=COUNTA($D$1:$D$4)textNO
Note that using COUNTA could be problematic if it is possible to have empty cells in your range, and you only want the condition met if every cell is populated with a Yes/No value.

1704989113231.png
 
Upvote 0
Note that using COUNTA could be problematic if it is possible to have empty cells in your range, and you only want the condition met if every cell is populated with a Yes/No value.

View attachment 104802
thanks Joe,

Here is corrected CF:
Book1
ABCD
1yes
2yes
3
4yes
5YES
Sheet4
Cells with Conditional Formatting
CellConditionCell FormatStop If True
A1Expression=COUNTIF($D$1:$D$5,"NO")=ROWS($D$1:$D$5)textNO
A1Expression=COUNTIF($D$1:$D$5,"YES")=ROWS($D$1:$D$5)textNO


Book1
ABCD
1yes
2yes
3yes
4yes
5YES
Sheet4
Cells with Conditional Formatting
CellConditionCell FormatStop If True
A1Expression=COUNTIF($D$1:$D$5,"NO")=ROWS($D$1:$D$5)textNO
A1Expression=COUNTIF($D$1:$D$5,"YES")=ROWS($D$1:$D$5)textNO


Book1
ABCD
1no
2NO
3NO
4NO
5NO
Sheet4
Cells with Conditional Formatting
CellConditionCell FormatStop If True
A1Expression=COUNTIF($D$1:$D$5,"NO")=ROWS($D$1:$D$5)textNO
A1Expression=COUNTIF($D$1:$D$5,"YES")=ROWS($D$1:$D$5)textNO
 
Upvote 0
Looks good.
Uses same concept as mine, just makes the formulas a little more dynamic, in case you don't want to hard-code the number of cells in the formula!
 
Upvote 0
Joe,
In your solution, where is the conditional formatting rule? If it is based on this formula being true:
Excel Formula:
=OR(COUNTIF(D1:D7,"Yes")=7,COUNTIF(D1:D7,"No")=7)
How do you know with this rule to make the cell red or green?
 
Upvote 0
Joe,
In your solution, where is the conditional formatting rule? If it is based on this formula being true:
Excel Formula:
=OR(COUNTIF(D1:D7,"Yes")=7,COUNTIF(D1:D7,"No")=7)
How do you know with this rule to make the cell red or green?
Ah, I misread and missed that they wanted two different colors, and just thought they wanted one color (same color) if ALL were "Yes" or ALL were "No".
If they want different colors for "Yes" and "No" (which I now see is probably what they want), they would need to break it up into two rules, like you did:

Green rule:
=COUNTIF(D1:D7,"Yes")=7

Red rule:
=COUNTIF(D1:D7,"No")=7
 
Upvote 0
You should simply be able to use a COUNTIF function in your Conditional Formatting formula, i.e.
Excel Formula:
=OR(COUNTIF(D1:D7,"Yes")=7,COUNTIF(D1:D7,"No")=7)
Thank you - but when all are no the cell also now goes green rather than red - does that make sense
thanks Joe,

Here is corrected CF:
Book1
ABCD
1yes
2yes
3
4yes
5YES
Sheet4
Cells with Conditional Formatting
CellConditionCell FormatStop If True
A1Expression=COUNTIF($D$1:$D$5,"NO")=ROWS($D$1:$D$5)textNO
A1Expression=COUNTIF($D$1:$D$5,"YES")=ROWS($D$1:$D$5)textNO


Book1
ABCD
1yes
2yes
3yes
4yes
5YES
Sheet4
Cells with Conditional Formatting
CellConditionCell FormatStop If True
A1Expression=COUNTIF($D$1:$D$5,"NO")=ROWS($D$1:$D$5)textNO
A1Expression=COUNTIF($D$1:$D$5,"YES")=ROWS($D$1:$D$5)textNO


Book1
ABCD
1no
2NO
3NO
4NO
5NO
Sheet4
Cells with Conditional Formatting
CellConditionCell FormatStop If True
A1Expression=COUNTIF($D$1:$D$5,"NO")=ROWS($D$1:$D$5)textNO
A1Expression=COUNTIF($D$1:$D$5,"YES")=ROWS($D$1:$D$5)textNO
Thank you :)
 
Upvote 0

Forum statistics

Threads
1,215,087
Messages
6,123,046
Members
449,092
Latest member
ikke

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top