Conditional Formatting based on Current Time ?

Aitch

Board Regular
Joined
Jan 27, 2019
Messages
105
Office Version
  1. 2010
Platform
  1. Windows
ft1RbJ77
Excel1.jpg



I'm using the NOW function to give the time in cell A1

I thought it would be easy to highlight the row which corresponds to the time, by EXACT matching A1 to the column B... but it's not working!

What's the best way to get this to work?

Thanks for your help!
 

Some videos you may like

Excel Facts

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.

jjasmith4

Board Regular
Joined
Aug 22, 2018
Messages
50
Ultimately NOW() is a floating-point number, and any quant will tell you, you shouldn't ever do exact comparisons with floating-point numbers, even with zero, because computers always have rounding errors. The general way to compare floating-point numbers is to subtract them and see if the absolute value of the difference is within a small tolerance.

So with numbers you would not use "=$A$1=B1" but instead "=ABS($A$1-B1)<0.00001" to determine equality to the fifth decimal place; with times you should use "=ABS($A$1-B1)<TIME(0,0,0.1)" to determine precision within a tenth of a second.


Note that I've used absolute addressing with $A$1, but not B1; this is so that when you copy formats downward, including conditional ones, $A$1 doesn't change, but B1 does.
 

DanteAmor

Well-known Member
Joined
Dec 3, 2018
Messages
12,594
Office Version
  1. 2007
Platform
  1. Windows
You can compare the text of both hours

=TEXT($A$1,"hh:mm")=TEXT(B3,"hh:mm")




For the time to update and move the highlight cell you can put the following code in the events of your sheet

Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    Application.Volatile
    Calculate
    DoEvents
End Sub

Every time you select any cell the time in A1 will be updated
 

DanteAmor

Well-known Member
Joined
Dec 3, 2018
Messages
12,594
Office Version
  1. 2007
Platform
  1. Windows

ADVERTISEMENT

Faster would be Range("A1").Calculate

Or simply calculate but I wanted to ensure the change of the formula to update the conditional format
 

DanteAmor

Well-known Member
Joined
Dec 3, 2018
Messages
12,594
Office Version
  1. 2007
Platform
  1. Windows
Use this formula:

=TEXT($A$1,"hh:mm")=TEXT($B3,"hh:mm")



It is important that in $B3 only have & before B

Apply To:
=$1:$1048576
 

Aitch

Board Regular
Joined
Jan 27, 2019
Messages
105
Office Version
  1. 2010
Platform
  1. Windows
Thank you for the replies guys!
 

Watch MrExcel Video

Forum statistics

Threads
1,122,970
Messages
5,599,106
Members
414,287
Latest member
Rbwester

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
Top