conditional formatting a cell when it is within a certain time bracket

Mr Marvin

New Member
Joined
Sep 8, 2021
Messages
31
Office Version
  1. 2019
Platform
  1. Windows
i am looking to automate the colour formatting of cells when i enter a time into a cell against the actual current time.
for example

the actual time is 11:00:00am

when i enter a time of 10:45:00 in cell D2 i want that to highlight green (so the time would be within 30 mins of the actual time), if i enter a time of 10:15:00am it would highlight amber (as it is between 30 mins and 45 mins) and if the time i enter was 10:00:00am (it would highlight red as it be over 45 minutes)

I have an VBA button which when keyed shows the actual time is in cell L9.

can this be done.

TIA
 

Excel Facts

Can a formula spear through sheets?
Use =SUM(January:December!E7) to sum E7 on all of the sheets from January through December
Yes, but each colour needs its own CF rule. I put the rules I used in G5:G7 since my excel won't show CF rules with XL2BB. The formula in E2 is
Excel Formula:
=IF(ABS($D$2-$L$9)<=30/1440,"green",IF(AND(ABS($D$2-$L$9)>30/1440,ABS($D$2-$L$9)<=45/1440),"amber","red"))
1712335279617.png
 
Upvote 0
Another option:

david763.xlsx
DL
1
29:30
3
4
5
6
7
8
94/5/2024 9:51
Sheet3
Cell Formulas
RangeFormula
L9L9=NOW()
Cells with Conditional Formatting
CellConditionCell FormatStop If True
D2Expression=ABS(MOD($L$9,1)-D2)>TIME(0,45,0)textNO
D2Expression=ABS(MOD($L$9,1)-D2)<TIME(0,30,0)textNO
D2Expression=ABS(MOD($L$9,1)-D2)<TIME(0,45,0)textNO


I'm not sure what else your macro does, but I just used the NOW() function for the date/time. You can refresh it with F9.
 
Upvote 0
@Eric W can I ask why the Mod() part of the formula? Is it just to ensure the value in L9 is a valid time?
 
Upvote 0
@Eric W can I ask why the Mod() part of the formula? Is it just to ensure the value in L9 is a valid time?
Yes, the NOW() function returns the combined day and time, which would throw off the CF formula. The date is the whole number part, and the time is the decimal part. The MOD(x,1) function removes the whole number part, just leaving the time. Now that you mention it though, I think both our formulas would have trouble with 11:50 PM and 00:03 AM being less than 30 minutes apart.
 
Upvote 0
thank you both for your help. after some playing i managed to work them out with your formulas.
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,178
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