Color based on No. Days

Johnboy28

Board Regular
Joined
Jun 22, 2013
Messages
198
Office Version
  1. 365
  2. 2019
  3. 2016
  4. 2013
  5. 2010
Platform
  1. Windows
Can anyone help - Based on the Production Date and code and today() Date - Need a formula to work out the "No. Days" over and Under and enter the colour (Red, Amber & Green based on table
Happy for you to change the format of the "No.Days" for formula to work

CodeColourNo. Days
72040Red37 Over
72040Amber37
72040Green35 Under
70559Red46 Over
70559Amber46
70559Green44 Under
73307Red35 Over
73307Amber35
73307Green33 Under
70059Red35 Over
70059Amber35
70059Green33 Under
Production DateCodeColour
14/05/2472040??
15/05/2472040
20/05/2473307
21/05/2470059
21/05/2473307
20/05/2472040
22/05/2470059
22/05/2473307
21/05/2472040
23/05/2470059
22/05/2472040
 

Excel Facts

Repeat Last Command
Pressing F4 adds dollar signs when editing a formula. When not editing, F4 repeats last command.
What do you want when the days difference falls into the gaps?
 
Upvote 0
Assuming the "gaps" between low and mid are to be GREEN, try this:

Book1
ABCDEFGH
1CodeColourNo. DaysCodeReference Days
270059Amber357005935
370059Green33 Under7055946
470059Red35 Over7204037
570559Amber467330735
670559Green44 Under
770559Red46 Over
872040Amber37
972040Green35 Under
1072040Red37 Over
1173307Amber35
1273307Green33 Under
1373307Red35 Over
14
15Today:2024-06-25
16RuleRuleRule
17Production DateCodeDays diffGreenAmberRed
182024-05-147204042FALSEFALSETRUE
192024-05-157204041FALSEFALSETRUE
202024-05-207330736FALSEFALSETRUE
212024-05-217005935FALSETRUEFALSE
222024-05-217330735FALSETRUEFALSE
232024-05-207204036TRUEFALSEFALSE
242024-05-227005934TRUEFALSEFALSE
252024-05-227330734TRUEFALSEFALSE
262024-05-217204035TRUEFALSEFALSE
272024-05-237005933TRUEFALSEFALSE
282024-05-227204034TRUEFALSEFALSE
Sheet1
Cell Formulas
RangeFormula
F18:F28F18=($C$15-B18)<LOOKUP($C18,$E$2:$E$5,$F$2:$F$5)
G18:G28G18=($C$15-B18)=LOOKUP($C18,$E$2:$E$5,$F$2:$F$5)
H18:H28H18=($C$15-B18)>LOOKUP($C18,$E$2:$E$5,$F$2:$F$5)
D18:D28D18=$C$15-B18
Cells with Conditional Formatting
CellConditionCell FormatStop If True
B18:B28Expression=($C$15-B18)>LOOKUP($C18,$E$2:$E$5,$F$2:$F$5)textNO
B18:B28Expression=($C$15-B18)=LOOKUP($C18,$E$2:$E$5,$F$2:$F$5)textNO
B18:B28Expression=($C$15-B18)<LOOKUP($C18,$E$2:$E$5,$F$2:$F$5)textNO
 
Upvote 0
Assuming the "gaps" between low and mid are to be GREEN, try this:

Book1
ABCDEFGH
1CodeColourNo. DaysCodeReference Days
270059Amber357005935
370059Green33 Under7055946
470059Red35 Over7204037
570559Amber467330735
670559Green44 Under
770559Red46 Over
872040Amber37
972040Green35 Under
1072040Red37 Over
1173307Amber35
1273307Green33 Under
1373307Red35 Over
14
15Today:2024-06-25
16RuleRuleRule
17Production DateCodeDays diffGreenAmberRed
182024-05-147204042FALSEFALSETRUE
192024-05-157204041FALSEFALSETRUE
202024-05-207330736FALSEFALSETRUE
212024-05-217005935FALSETRUEFALSE
222024-05-217330735FALSETRUEFALSE
232024-05-207204036TRUEFALSEFALSE
242024-05-227005934TRUEFALSEFALSE
252024-05-227330734TRUEFALSEFALSE
262024-05-217204035TRUEFALSEFALSE
272024-05-237005933TRUEFALSEFALSE
282024-05-227204034TRUEFALSEFALSE
Sheet1
Cell Formulas
RangeFormula
F18:F28F18=($C$15-B18)<LOOKUP($C18,$E$2:$E$5,$F$2:$F$5)
G18:G28G18=($C$15-B18)=LOOKUP($C18,$E$2:$E$5,$F$2:$F$5)
H18:H28H18=($C$15-B18)>LOOKUP($C18,$E$2:$E$5,$F$2:$F$5)
D18:D28D18=$C$15-B18
Cells with Conditional Formatting
CellConditionCell FormatStop If True
B18:B28Expression=($C$15-B18)>LOOKUP($C18,$E$2:$E$5,$F$2:$F$5)textNO
B18:B28Expression=($C$15-B18)=LOOKUP($C18,$E$2:$E$5,$F$2:$F$5)textNO
B18:B28Expression=($C$15-B18)<LOOKUP($C18,$E$2:$E$5,$F$2:$F$5)textNO

Thank you.

Is it possible to just include colour as per below sample. I have included the number of dayss between today's date and production date.

CodeColourNo. Days
72040Red37 Over
72040Amber37
72040Green35 Under
70559Red46 Over
70559Amber46
70559Green44Under
73307Red35 Over
73307Amber35
73307Green33 Under
70059Red35 Over
70059Amber35
70059Green33 Under
today30/05/2024
Production DateCodeNo. DaysColour
14/05/247204016Green
15/05/247204015
20/05/247330710
21/05/24700599
21/05/24733079
20/05/247204010
22/05/24700598
22/05/24733078
21/05/24720409
23/05/24700597
22/05/24720408
 
Upvote 0
are you asking to see the words of the color in text?

If so, then this:

Book1
ABCDEFGH
1CodeColourNo. DaysCodeReference Days
270059Amber357005935
370059Green33 Under7055946
470059Red35 Over7204037
570559Amber467330735
670559Green44 Under
770559Red46 Over
872040Amber37
972040Green35 Under
1072040Red37 Over
1173307Amber35
1273307Green33 Under
1373307Red35 Over
14
15Today:45468
16Color CalcRuleRuleRule
17Production DateCodeDays diffGreenAmberRed
182024-05-147204042RedFALSEFALSETRUE
192024-05-157204041RedFALSEFALSETRUE
202024-05-207330736RedFALSEFALSETRUE
212024-05-217005935AmberFALSETRUEFALSE
222024-05-217330735AmberFALSETRUEFALSE
232024-05-207204036GreenTRUEFALSEFALSE
242024-05-227005934GreenTRUEFALSEFALSE
252024-05-227330734GreenTRUEFALSEFALSE
262024-05-217204035GreenTRUEFALSEFALSE
272024-05-237005933GreenTRUEFALSEFALSE
282024-05-227204034GreenTRUEFALSEFALSE
Sheet3
Cell Formulas
RangeFormula
D18:D28D18=$C$15-B18
E18:E28E18=SWITCH(SIGN(($C$15-B18)-LOOKUP($C18,$E$2:$E$5,$F$2:$F$5)),-1,"Green",0,"Amber",1,"Red")
F18:F28F18=($C$15-B18)<LOOKUP($C18,$E$2:$E$5,$F$2:$F$5)
G18:G28G18=($C$15-B18)=LOOKUP($C18,$E$2:$E$5,$F$2:$F$5)
H18:H28H18=($C$15-B18)>LOOKUP($C18,$E$2:$E$5,$F$2:$F$5)
 
Last edited:
Upvote 0
are you asking to see the words of the color in text?

If so, then this:

Book1
ABCDEFGH
1CodeColourNo. DaysCodeReference Days
270059Amber357005935
370059Green33 Under7055946
470059Red35 Over7204037
570559Amber467330735
670559Green44 Under
770559Red46 Over
872040Amber37
972040Green35 Under
1072040Red37 Over
1173307Amber35
1273307Green33 Under
1373307Red35 Over
14
15Today:45468
16Color CalcRuleRuleRule
17Production DateCodeDays diffGreenAmberRed
182024-05-147204042RedFALSEFALSETRUE
192024-05-157204041RedFALSEFALSETRUE
202024-05-207330736RedFALSEFALSETRUE
212024-05-217005935AmberFALSETRUEFALSE
222024-05-217330735AmberFALSETRUEFALSE
232024-05-207204036GreenTRUEFALSEFALSE
242024-05-227005934GreenTRUEFALSEFALSE
252024-05-227330734GreenTRUEFALSEFALSE
262024-05-217204035GreenTRUEFALSEFALSE
272024-05-237005933GreenTRUEFALSEFALSE
282024-05-227204034GreenTRUEFALSEFALSE
Sheet3
Cell Formulas
RangeFormula
D18:D28D18=$C$15-B18
E18:E28E18=SWITCH(SIGN(($C$15-B18)-LOOKUP($C18,$E$2:$E$5,$F$2:$F$5)),-1,"Green",0,"Amber",1,"Red")
F18:F28F18=($C$15-B18)<LOOKUP($C18,$E$2:$E$5,$F$2:$F$5)
G18:G28G18=($C$15-B18)=LOOKUP($C18,$E$2:$E$5,$F$2:$F$5)
H18:H28H18=($C$15-B18)>LOOKUP($C18,$E$2:$E$5,$F$2:$F$5)
Perfect - Thank you
 
Upvote 0
Happy to help. But, I'm still not entirely sure I answered the exact question as there are gaps in your range of values that were not considered. I did not account for that. I asked about this and there was no answer. For example what happens in a scenario with days of 36 and Code: 72040?

Best Wishes.
 
Upvote 0
I have made a mistake on the days. I will adjust so the days are covered. Thanks again for your help.
 
Upvote 0
Happy to help. But, I'm still not entirely sure I answered the exact question as there are gaps in your range of values that were not considered. I did not account for that. I asked about this and there was no answer. For example what happens in a scenario with days of 36 and Code: 72040?

Best Wishes.
Sorry to be a pain - Are you able to amend formula based on the below table. I have added to Days Diff Range so I cover the gaps. I hope this makes sense. Thank you

CodeColourDays DiffDays Diff
72040Red37100
72040Amber3737
72040Green036
70559Red46100
70559Amber4646
70559Green045
73307Red35100
73307Amber3535
73307Green034
70059Red35100
70059Amber3535
70059Green034
Today31/05/2024
Production DateCodeDays DiffColour
14/05/247204017.00
#N/A​
15/05/247204016.00
20/05/247330711.00
21/05/247005910.00
21/05/247330710.00
20/05/247204011.00
22/05/24700599.00
22/05/24733079.00
21/05/247204010.00
23/05/24700598.00
22/05/24720409.00
 
Upvote 0

Forum statistics

Threads
1,224,818
Messages
6,181,151
Members
453,021
Latest member
Justyna P

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