Conditional Format based on IF statement

wring

New Member
Joined
Sep 30, 2015
Messages
4
I would like every cell in column A formatted either Red or Green based on the following logic:

If the corresponding (same row) cell in column B is a 0 then a positive number in Column A should be highlighted/filled Red. If column B is 0 and Column A is negative number then Column A cell should be highlighted/filled Green.

Similarly if Column B is a 1, and Column A is positive, then Column A cell should be Green. If Column B is a 1, and Column A is a negative, then Column A cell should be Red.

See the below table for the logic I'm looking for with color coding.

10
-10
11
-11

<tbody>
</tbody>

Thanks in advance for your help.
 

Excel Facts

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.
Select your A column and make 4 new conditional formatting rules(use formula to determine format):

=AND(A1>0,B1=0) Format font color red
=AND(A1<0,B1=0) Format font color green
=AND(A1>0,B1=1) Format font color green
=AND(A1<0,B1=1) Format font color red

Or 2 rules:

=OR(AND(A1<0,B1=0),AND(A1>0,B1=1)) Format font color green
=OR(AND(A1>0,B1=0),AND(A1<0,B1=1)) Format font color red
 
Last edited:
Upvote 0
If the corresponding (same row) cell in column B is a 0 then a positive number in Column A should be highlighted/filled Red. If column B is 0 and Column A is negative number then Column A cell should be highlighted/filled Green.

Similarly if Column B is a 1, and Column A is positive, then Column A cell should be Green. If Column B is a 1, and Column A is a negative, then Column A cell should be Red.

setup conditional formatting using the following formulas

What happens if zero ?

RED
=OR(AND(B1=0, A1>0), AND(B1=1,A1<0))

GREEN
=OR(AND(B1=1, A1>0) , AND(B1=0, A1<0))

Heres how to setup the conditional format

for 2007, 2010 or 2013 excel version
Conditional Formatting


Highlight applicable range >>

A1 : A1000



Home Tab >> Styles >> Conditional Formatting
New Rule >> Use a formula to determine which cells to format
Edit the Rule Description: Format values where this formula is true:



=OR(AND(B1=0, A1>0), AND(B1=1,A1<0))



Format… [Number, Font, Border, Fill] - format for RED
choose the format you would like to apply when the condition is true
OK >> OK

Set-up a new rule for GREEN
 
Upvote 0
=AND(A1>0,B1=0) Format font color red
=AND(A1<0,B1=0) Format font color green
=AND(A1>0,B1=1) Format font color green
=AND(A1<0,B1=1) Format font color red
Could also be done just using two Rules:

=OR(AND(A1>0,B1=0),AND(A1<0,B1=1)) Format font color red
=OR(AND(A1<0,B1=0),AND(A1>0,B1=1)) Format font color green

 
Upvote 0
Could also be done just using two Rules:

=OR(AND(A1>0,B1=0),AND(A1<0,B1=1)) Format font color red
=OR(AND(A1<0,B1=0),AND(A1>0,B1=1)) Format font color green


Aye, noted and fixed while you posted, thanks! ;)
 
Upvote 0
I tried using the two formulas you listed and no formatting occurred. Any idea maybe what I did wrong?

Under the 'Applies to' column in Rules Manager I have the entire column selected (A12:A76)
 
Upvote 0
Did you change the rules to start at A12 and B12?
 
Upvote 0
Note that it also makes a difference if they are numeric entries or text (if the numbers appear left-justified in your cells, they are probably text and not numeric).
To reference text entries, you need to surround your values with double-quotes, i.e.
=OR(AND(A1>0,B1="0"),AND(A1<0,B1="1"))
 
Upvote 0
They were non-numeric. Once I put in quotations it worked great! Thanks for the help!
 
Upvote 0

Forum statistics

Threads
1,215,339
Messages
6,124,381
Members
449,155
Latest member
ravioli44

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