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
 
Are you asking for the values between the two ranges to be amber?
 
Upvote 0

Excel Facts

Last used cell?
Press Ctrl+End to move to what Excel thinks is the last used cell.
Also, which version of Excel are you actually using this formula in? You have many versons listed. I suggest you change that to the one you most frequently use, or you'll need to identify which version you use whenever you post questions. The later versions of excel, particularly 365 have much more efficient and helpful functions.
 
Upvote 0
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
I've looked at this again. all you did was seem to add an upper limit on the RED. What happens if the days go in excess of 100? Is there a 4th color you want? Also I'd really suggest, unless there is a compelling reason, to create a matrix for your "days difference" ranges instead of a flat file. You example does not give any idea of expectations, so please change the days (even if not always a likely scenario) so that you cover all the different combinations of code and days different.
 
Upvote 0
I've looked at this again. all you did was seem to add an upper limit on the RED. What happens if the days go in excess of 100? Is there a 4th color you want? Also I'd really suggest, unless there is a compelling reason, to create a matrix for your "days difference" ranges instead of a flat file. You example does not give any idea of expectations, so please change the days (even if not always a likely scenario) so that you cover all the different combinations of code and days different.
I have amended the range - The days will never go over 100, I have increase to 500.

CodeColourDays DiffDays Diff
72040Red38500
72040Amber3737
72040Green036
70559Red47500
70559Amber4646
70559Green045
73307Red36500
73307Amber3535
73307Green034
70059Red36500
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
I have amended the range - The days will never go over 100, I have increase to 500.

CodeColourDays DiffDays Diff
72040Red38500
72040Amber3737
72040Green036
70559Red47500
70559Amber4646
70559Green045
73307Red36500
73307Amber3535
73307Green034
70059Red36500
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
I still don't understand why you even want to do that? If the RED range starts at the middle number and you don't care how high the "high" number is why even have a high number?????

All of your Greens start at ZERO. the only number I think you need is the middle number. Which is what I put in the first solution i offered. Please show me an example of where this does not work?
 
Upvote 0
I cant get your first solution to work? Happy to use the below

=SWITCH(SIGN(($C$8-A11)-LOOKUP($B11,$A$2:$A$5,$B$2:$B$5)),-1,"Green",0,"Amber",1,"Red")

codereference days
7005935
7055946
7204037
7330735
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
I'm using it again, here:
What kind of error are you getting? What cell? What formula is in that cell? What is the result of the formula?


Book2
ABCDEFGHIJK
1CodeColourNo. DaysCodeReference Days
270059Amber35357005935
370059Green0347055946
470059Red355007204037
570559Amber46467330735
670559Green045
770559Red46500
872040Amber3737
972040Green036
1072040Red37500
1173307Amber3535
1273307Green034
1373307Red35500
14ConditionalConditionalConditional
15Today:2024-06-25FormattingFormattingFormatting
16RuleRuleRule
17Production DateCodeDays diffGreenAmberRed
182024-05-137204043RedFALSEFALSETRUE
192024-04-087204078RedFALSEFALSETRUE
202024-02-0473307142RedFALSEFALSETRUE
212024-05-217005935AmberFALSETRUEFALSE
222024-04-247330762RedFALSEFALSETRUE
232024-04-237204063RedFALSEFALSETRUE
242024-05-317005925GreenTRUEFALSEFALSE
252024-05-307330726GreenTRUEFALSEFALSE
262024-04-137204073RedFALSEFALSETRUE
272024-05-257005931GreenTRUEFALSEFALSE
282024-03-287204089RedFALSEFALSETRUE
292024-02-0872040138RedFALSEFALSETRUE
302024-04-287204058RedFALSEFALSETRUE
312024-04-157330771RedFALSEFALSETRUE
322024-05-107055946AmberFALSETRUEFALSE
332024-05-317330725GreenTRUEFALSEFALSE
342024-05-027204054RedFALSEFALSETRUE
352024-03-1170059106RedFALSEFALSETRUE
362024-05-047330752RedFALSEFALSETRUE
372024-04-167204070RedFALSEFALSETRUE
382024-02-0770059139RedFALSEFALSETRUE
392024-05-297204027GreenTRUEFALSEFALSE
402024-05-197204037AmberFALSETRUEFALSE
412024-02-0972040137RedFALSEFALSETRUE
422024-05-317330725GreenTRUEFALSEFALSE
432024-05-087005948RedFALSEFALSETRUE
442024-02-1273307134RedFALSEFALSETRUE
452024-05-067204050RedFALSEFALSETRUE
462024-04-207005966RedFALSEFALSETRUE
472024-05-217330735AmberFALSETRUEFALSE
482024-05-137204043RedFALSEFALSETRUE
492024-04-267005960RedFALSEFALSETRUE
502024-03-227204095RedFALSEFALSETRUE
512024-05-317330725GreenTRUEFALSEFALSE
522024-05-197005937RedFALSEFALSETRUE
532024-03-277330790RedFALSEFALSETRUE
Sheet4
Cell Formulas
RangeFormula
D18:D53D18=$C$15-B18
E18:E53E18=SWITCH(SIGN(($C$15-B18)-LOOKUP($C18,$F$2:$F$5,$G$2:$G$5)),-1,"Green",0,"Amber",1,"Red")
I18:I53I18=($C$15-B18)<LOOKUP($C18,$F$2:$F$5,$G$2:$G$5)
J18:J53J18=($C$15-B18)=LOOKUP($C18,$F$2:$F$5,$G$2:$G$5)
K18:K53K18=($C$15-B18)>LOOKUP($C18,$F$2:$F$5,$G$2:$G$5)
Cells with Conditional Formatting
CellConditionCell FormatStop If True
B18:B53Expression=($C$15-B18)>LOOKUP($C18,$F$2:$F$5,$G$2:$G$5)textNO
B18:B53Expression=($C$15-B18)=LOOKUP($C18,$F$2:$F$5,$G$2:$G$5)textNO
B18:B53Expression=($C$15-B18)<LOOKUP($C18,$F$2:$F$5,$G$2:$G$5)textNO
 
Upvote 0
I'm using it again, here:
What kind of error are you getting? What cell? What formula is in that cell? What is the result of the formula?


Book2
ABCDEFGHIJK
1CodeColourNo. DaysCodeReference Days
270059Amber35357005935
370059Green0347055946
470059Red355007204037
570559Amber46467330735
670559Green045
770559Red46500
872040Amber3737
972040Green036
1072040Red37500
1173307Amber3535
1273307Green034
1373307Red35500
14ConditionalConditionalConditional
15Today:2024-06-25FormattingFormattingFormatting
16RuleRuleRule
17Production DateCodeDays diffGreenAmberRed
182024-05-137204043RedFALSEFALSETRUE
192024-04-087204078RedFALSEFALSETRUE
202024-02-0473307142RedFALSEFALSETRUE
212024-05-217005935AmberFALSETRUEFALSE
222024-04-247330762RedFALSEFALSETRUE
232024-04-237204063RedFALSEFALSETRUE
242024-05-317005925GreenTRUEFALSEFALSE
252024-05-307330726GreenTRUEFALSEFALSE
262024-04-137204073RedFALSEFALSETRUE
272024-05-257005931GreenTRUEFALSEFALSE
282024-03-287204089RedFALSEFALSETRUE
292024-02-0872040138RedFALSEFALSETRUE
302024-04-287204058RedFALSEFALSETRUE
312024-04-157330771RedFALSEFALSETRUE
322024-05-107055946AmberFALSETRUEFALSE
332024-05-317330725GreenTRUEFALSEFALSE
342024-05-027204054RedFALSEFALSETRUE
352024-03-1170059106RedFALSEFALSETRUE
362024-05-047330752RedFALSEFALSETRUE
372024-04-167204070RedFALSEFALSETRUE
382024-02-0770059139RedFALSEFALSETRUE
392024-05-297204027GreenTRUEFALSEFALSE
402024-05-197204037AmberFALSETRUEFALSE
412024-02-0972040137RedFALSEFALSETRUE
422024-05-317330725GreenTRUEFALSEFALSE
432024-05-087005948RedFALSEFALSETRUE
442024-02-1273307134RedFALSEFALSETRUE
452024-05-067204050RedFALSEFALSETRUE
462024-04-207005966RedFALSEFALSETRUE
472024-05-217330735AmberFALSETRUEFALSE
482024-05-137204043RedFALSEFALSETRUE
492024-04-267005960RedFALSEFALSETRUE
502024-03-227204095RedFALSEFALSETRUE
512024-05-317330725GreenTRUEFALSEFALSE
522024-05-197005937RedFALSEFALSETRUE
532024-03-277330790RedFALSEFALSETRUE
Sheet4
Cell Formulas
RangeFormula
D18:D53D18=$C$15-B18
E18:E53E18=SWITCH(SIGN(($C$15-B18)-LOOKUP($C18,$F$2:$F$5,$G$2:$G$5)),-1,"Green",0,"Amber",1,"Red")
I18:I53I18=($C$15-B18)<LOOKUP($C18,$F$2:$F$5,$G$2:$G$5)
J18:J53J18=($C$15-B18)=LOOKUP($C18,$F$2:$F$5,$G$2:$G$5)
K18:K53K18=($C$15-B18)>LOOKUP($C18,$F$2:$F$5,$G$2:$G$5)
Cells with Conditional Formatting
CellConditionCell FormatStop If True
B18:B53Expression=($C$15-B18)>LOOKUP($C18,$F$2:$F$5,$G$2:$G$5)textNO
B18:B53Expression=($C$15-B18)=LOOKUP($C18,$F$2:$F$5,$G$2:$G$5)textNO
B18:B53Expression=($C$15-B18)<LOOKUP($C18,$F$2:$F$5,$G$2:$G$5)textNO

..=SWITCH(SIGN(($C$15-B18)-LOOKUP($C18,$F$2:$F$5,$G$2:$G$5)),-1,"Green",0,"Amber",1,"Red") I'm pasting your formula in Cell E18. Error is #N/A

Could it be my version of Excel? Office 365
 
Upvote 0
I use 365.

do you have two dots in front of the equal sign in the formula, or is that a typo when you pasted the expression?

What value is in cell C15? - This should be the reference date (I used a fixed date to get calculations, but would probably want TODAY() in your production sheet.
Confirm it is a date value (Use the formatting tool and change to NUMBER, if it doesn't change to a numeric value it is TEXT, and you need to fix.)​
What value is in cell B18? - This should be the first production date in your production date column. (ensure it is a date value test the same as for C15.)
What value is in cell C18? - This should be the code number associated with your first production date. IT IS NUMERIC, not text (add decimals using decimal
formatting - if you don't get decimal zeros then the cell is not numeric).​
What values are in cells F2:F5? - These are the code numbers look up, these should be in ascending sequence and NUMERIC. (test the same as C18 suggested above)
What values are in cells G2:G5? - These are the threshold numbers returned by the lookup, these should also be NUMERIC. (test the same as C18 suggested above)

Why not try to paste the entire mini worksheet (click the "copy" icon in the top left corner of mini sheet) onto a fresh worksheet.
The formulas should work. But, the conditional formatting will not transfer over and you need to build that with the formulas in the "Cells With Conditional Formatting" portion of the mini sheet post.
 
Upvote 0
I use 365.

do you have two dots in front of the equal sign in the formula, or is that a typo when you pasted the expression?

What value is in cell C15? - This should be the reference date (I used a fixed date to get calculations, but would probably want TODAY() in your production sheet.
Confirm it is a date value (Use the formatting tool and change to NUMBER, if it doesn't change to a numeric value it is TEXT, and you need to fix.)​
What value is in cell B18? - This should be the first production date in your production date column. (ensure it is a date value test the same as for C15.)
What value is in cell C18? - This should be the code number associated with your first production date. IT IS NUMERIC, not text (add decimals using decimal
formatting - if you don't get decimal zeros then the cell is not numeric).​
What values are in cells F2:F5? - These are the code numbers look up, these should be in ascending sequence and NUMERIC. (test the same as C18 suggested above)
What values are in cells G2:G5? - These are the threshold numbers returned by the lookup, these should also be NUMERIC. (test the same as C18 suggested above)

Why not try to paste the entire mini worksheet (click the "copy" icon in the top left corner of mini sheet) onto a fresh worksheet.
The formulas should work. But, the conditional formatting will not transfer over and you need to build that with the formulas in the "Cells With Conditional Formatting" portion of the mini sheet post.
Thank for all your help. I copied the Mini worksheet you did and pasted into my sheet and it all worked. Not sure what I did wrong. All good now. Thanks again. Appreciate it.
 
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