Conditional Formatting question

xbaca

New Member
Joined
Oct 17, 2021
Messages
8
Office Version
  1. 365
Platform
  1. Windows
Hello everyone,

I can't figure out how to accomplish following task:

I would like to use conditional formatting to color certain cells based on how big is the difference when comparing two cells above each other.

Looking at the example below, Row 2 is the starting value and Row 3 is one that I would like to highlight certain cells based on a difference in comparison to Row 2 ,only comparing cells that are above each other in each column. Continuing down, Row 4 would be compared to Row 3 and so on as I'm adding more rows when new period begins.

Scenario1:
I would highlight only negative trend, which would be value going up in Column A, from example below it would be cell A3 being higher than A2, so A3 should be light shade of red as the difference is not big, cell A4 would remain without highlight as we want this number to go down.
Column B we want this number to be more negative, in example below B3 is less negative in comparison to B2, therefore it should be light red, B4 in comparison to B3 is even more significant, therefore it should be darker shade of red.

Column C and D is the same, just another period.

Scenario2:
Same as the above example with addition to add green highlight also to positive trend, meaning lower positive number when comparing cells in Column A and higher negative number in Column B.

testcase_.xlsx
ABCDEFGH
14.9. - 1.10.2.10. - 29.10.30.10. - 26.11.27.11. - 24.12.
21,936,474-3,720,7041,250,217-3,007,5721,046,469-2,703,316631,320-1,551,938
32,004,340-3,487,9241,467,568-3,065,293858,564-2,738,814752,123-1,541,196
41,830,979-2,941,5751,404,738-2,436,402898,630-2,951,639724,023-1,349,222
List1

This would be the result for Scenario2:
testcase_.xlsx
ABCDEFGH
14.9. - 1.10.2.10. - 29.10.30.10. - 26.11.27.11. - 24.12.
21,936,474-3,720,7041,250,217-3,007,5721,046,469-2,703,316631,320-1,551,938
32,004,340-3,487,9241,467,568-3,065,293858,564-2,738,814752,123-1,541,196
41,830,979-2,941,5751,404,738-2,436,402898,630-2,951,639724,023-1,349,222
List1


Thanks a lot for your input!
 

Excel Facts

Does the VLOOKUP table have to be sorted?
No! when you are using an exact match, the VLOOKUP table can be in any order. Best-selling items at the top is actually the best.
In column B, the trend between B3 and B4 is positive, but highlight red why? Same thing for column F, the trend between F3 and F4 is negative but it's highlighted green. Why?
 
Upvote 0
In column B, the trend between B3 and B4 is positive, but highlight red why? Same thing for column F, the trend between F3 and F4 is negative but it's highlighted green. Why?
Disregard this for now.

Edit: Why is C4 light red? Shouldn't it be light green?
 
Last edited:
Upvote 0
In column B, the trend between B3 and B4 is positive, but highlight red why? Same thing for column F, the trend between F3 and F4 is negative but it's highlighted green. Why?

Column A: this number is always positive, a lower number is what you want - green, a higher number - red
Column B: this number is always negative, a lower number is what you want - green, a higher number - red

This pattern repeats to the next periods C-D, E-F, G-H.

There is actually a mistake in C4, this cell should be light green and the number is lower than C3.

Hopefully, this is a better explanation.
 
Upvote 0
Column A: this number is always positive, a lower number is what you want - green, a higher number - red
Column B: this number is always negative, a lower number is what you want - green, a higher number - red

This pattern repeats to the next periods C-D, E-F, G-H.

There is actually a mistake in C4, this cell should be light green and the number is lower than C3.

Hopefully, this is a better explanation.

Okay, here is what I have come up with. You will have to adjust the ranges in the CF formulas for the varying degrees of difference. I could only guess at what they were. I might add, this only satisfies scenario 2. For scenario 1, you would just use the red rules. Also note the different ranges for each set of formulas, one for the first column in each period, another for the second column in each period.

Book2
ABCDEFGH
14.9. - 1.10.2.10. - 29.10.30.10. - 26.11.27.11. - 24.12.
21,936,474-37207041,250,217-30075721,046,469-2703316631,320-1551938
32,004,340-34879241,467,568-3065293858,564-2738814752,123-1541196
41,830,979-29415751,404,738-2436402898,630-2951639724,023-1349222
Sheet1
Cells with Conditional Formatting
CellConditionCell FormatStop If True
B3:B4,D3:D4,F3:F4,H3:H4Expression=AND((B3-B2)/B2>0,(B3-B2)/B2<=0.09)=TRUEtextNO
B3:B4,D3:D4,F3:F4,H3:H4Expression=AND((B3-B2)/B2>0.09,(B3-B2)/B2<=0.19)=TRUEtextNO
B3:B4,D3:D4,F3:F4,H3:H4Expression=(B3-B2)/B2>0.19textNO
B3:B4,D3:D4,F3:F4,H3:H4Expression=AND((B3-B2)/B2<0,(B3-B2)/B2>=-0.09)=TRUEtextNO
B3:B4,D3:D4,F3:F4,H3:H4Expression=AND((B3-B2)/B2<-0.09,(B3-B2)/B2>=-0.19)=TRUEtextNO
B3:B4,D3:D4,F3:F4,H3:H4Expression=(B3-B2)/B2<-0.19textNO
A3:A4,C3:C4,E3:E4,G3:G4Expression=AND((A2-A3)/A2>0,(A2-A3)/A2<=0.09)=TRUEtextNO
A3:A4,C3:C4,E3:E4,G3:G4Expression=AND((A2-A3)/A2>0.09,(A2-A3)/A2<=0.19)=TRUEtextNO
A3:A4,C3:C4,E3:E4,G3:G4Expression=(A2-A3)/A2>0.19textNO
A3:A4,C3:C4,E3:E4,G3:G4Expression=AND((A2-A3)/A2<0,(A2-A3)/A2>=-0.09)=TRUEtextNO
A3:A4,C3:C4,E3:E4,G3:G4Expression=AND((A2-A3)/A2<-0.09,(A2-A3)/A2>=-0.19)=TRUEtextNO
A3:A4,C3:C4,E3:E4,G3:G4Expression=(A2-A3)/A2<-0.19textNO
 
Last edited:
Upvote 0
I got your solution running in my larger scale. Thanks

One more question, Is it possible to intead of comparing % difference in between two cells to set various thresholds for each shade?

For example: below 50k difference - light red, from 50k-200k - red, from 200k and above dark red.. and same for green conditions
Following your previous solution, bottom two cells in Column A are dark red which grabs your attention, but those changes are minor.

testcase_.xlsx
AB
122161-1521403
233508-1642824
350512-1394712
List2
Cells with Conditional Formatting
CellConditionCell FormatStop If True
A2:A3Expression=(A1-A2)/A1<-0.19textNO
A2:A3Expression=A((A1-A2)/A1<-0.09,(A1-A2)/A1>=-0.19)=PRAVDAtextNO
A2:A3Expression=A((A1-A2)/A1<0,(A1-A2)/A1>=-0.09)=PRAVDAtextNO
A2:A3Expression=(A1-A2)/A1>0.19textNO
A2:A3Expression=A((A1-A2)/A1>0.09,(A1-A2)/A1<=0.19)=PRAVDAtextNO
A2:A3Expression=A((A1-A2)/A1>0,(A1-A2)/A1<=0.09)=PRAVDAtextNO
B2:B3Expression=(B2-B1)/B1<-0.19textNO
B2:B3Expression=A((B2-B1)/B1<-0.09,(B2-B1)/B1>=-0.19)=PRAVDAtextNO
B2:B3Expression=A((B2-B1)/B1<0,(B2-B1)/B1>=-0.09)=PRAVDAtextNO
B2:B3Expression=(B2-B1)/B1>0.19textNO
B2:B3Expression=A((B2-B1)/B1>0.09,(B2-B1)/B1<=0.19)=PRAVDAtextNO
B2:B3Expression=A((B2-B1)/B1>0,(B2-B1)/B1<=0.09)=PRAVDAtextNO
 
Upvote 0
I got your solution running in my larger scale. Thanks

One more question, Is it possible to intead of comparing % difference in between two cells to set various thresholds for each shade?

For example: below 50k difference - light red, from 50k-200k - red, from 200k and above dark red.. and same for green conditions
Following your previous solution, bottom two cells in Column A are dark red which grabs your attention, but those changes are minor.

testcase_.xlsx
AB
122161-1521403
233508-1642824
350512-1394712
List2
Cells with Conditional Formatting
CellConditionCell FormatStop If True
A2:A3Expression=(A1-A2)/A1<-0.19textNO
A2:A3Expression=A((A1-A2)/A1<-0.09,(A1-A2)/A1>=-0.19)=PRAVDAtextNO
A2:A3Expression=A((A1-A2)/A1<0,(A1-A2)/A1>=-0.09)=PRAVDAtextNO
A2:A3Expression=(A1-A2)/A1>0.19textNO
A2:A3Expression=A((A1-A2)/A1>0.09,(A1-A2)/A1<=0.19)=PRAVDAtextNO
A2:A3Expression=A((A1-A2)/A1>0,(A1-A2)/A1<=0.09)=PRAVDAtextNO
B2:B3Expression=(B2-B1)/B1<-0.19textNO
B2:B3Expression=A((B2-B1)/B1<-0.09,(B2-B1)/B1>=-0.19)=PRAVDAtextNO
B2:B3Expression=A((B2-B1)/B1<0,(B2-B1)/B1>=-0.09)=PRAVDAtextNO
B2:B3Expression=(B2-B1)/B1>0.19textNO
B2:B3Expression=A((B2-B1)/B1>0.09,(B2-B1)/B1<=0.19)=PRAVDAtextNO
B2:B3Expression=A((B2-B1)/B1>0,(B2-B1)/B1<=0.09)=PRAVDAtextNO
Yes, that can be done, and with half the rules. A6:H7 is just my reference to see the actual difference and compare the highlights by value difference. Here is what I have:

Book1
ABCDEFGH
14.9. - 1.10.2.10. - 29.10.30.10. - 26.11.27.11. - 24.12.
21,936,473.61(3,720,704)1,250,217.22(3,007,572)1,046,469.29(2,703,316)631,319.72(1,551,938)
32,004,340.04(3,487,924)1,467,568.12(3,065,293)858,564.00(2,738,814)752,123.31(1,541,196)
41,830,978.74(2,941,575)1,404,737.53(2,436,402)898,630.09(2,951,639)724,023.41(1,349,222)
5
6(67,866)(232,780)(217,351)57,721187,90535,499(120,804)(10,742)
7173,361(546,349)62,831(628,891)(40,066)212,82528,100(191,974)
Sheet1
Cell Formulas
RangeFormula
A6:H7A6=A2-A3
Cells with Conditional Formatting
CellConditionCell FormatStop If True
A3:H4Expression=AND((A2-A3)>0,(A2-A3)<50000)=TRUEtextNO
A3:H4Expression=AND((A2-A3)>=50000,(A2-A3)<=200000)=TRUEtextNO
A3:H4Expression=(A2-A3)>200000textNO
A3:H4Expression=AND((A2-A3)<0,(A2-A3)>-50000)=TRUEtextNO
A3:H4Expression=AND((A2-A3)<=-50000,(A2-A3)>=-200000)=TRUEtextNO
A3:H4Expression=(A2-A3)<-200000textNO
 
Upvote 1
Solution
Yes, that can be done, and with half the rules. A6:H7 is just my reference to see the actual difference and compare the highlights by value difference. Here is what I have:

Book1
ABCDEFGH
14.9. - 1.10.2.10. - 29.10.30.10. - 26.11.27.11. - 24.12.
21,936,473.61(3,720,704)1,250,217.22(3,007,572)1,046,469.29(2,703,316)631,319.72(1,551,938)
32,004,340.04(3,487,924)1,467,568.12(3,065,293)858,564.00(2,738,814)752,123.31(1,541,196)
41,830,978.74(2,941,575)1,404,737.53(2,436,402)898,630.09(2,951,639)724,023.41(1,349,222)
5
6(67,866)(232,780)(217,351)57,721187,90535,499(120,804)(10,742)
7173,361(546,349)62,831(628,891)(40,066)212,82528,100(191,974)
Sheet1
Cell Formulas
RangeFormula
A6:H7A6=A2-A3
Cells with Conditional Formatting
CellConditionCell FormatStop If True
A3:H4Expression=AND((A2-A3)>0,(A2-A3)<50000)=TRUEtextNO
A3:H4Expression=AND((A2-A3)>=50000,(A2-A3)<=200000)=TRUEtextNO
A3:H4Expression=(A2-A3)>200000textNO
A3:H4Expression=AND((A2-A3)<0,(A2-A3)>-50000)=TRUEtextNO
A3:H4Expression=AND((A2-A3)<=-50000,(A2-A3)>=-200000)=TRUEtextNO
A3:H4Expression=(A2-A3)<-200000textNO
Works great, a lot better clarity, thanks.
 
Upvote 0

Forum statistics

Threads
1,223,882
Messages
6,175,164
Members
452,615
Latest member
bogeys2birdies

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