# Conditional Formatting based on Current Time ?

#### Aitch

##### Board Regular

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!

### Excel Facts

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.
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.

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

Faster would be Range("A1").Calculate

Faster would be Range("A1").Calculate

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

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

Thank you for the replies guys!

You're welcome

Replies
3
Views
380
Replies
0
Views
225
Replies
0
Views
79
Replies
1
Views
93
Replies
7
Views
114

1,206,828
Messages
6,075,103
Members
446,121
Latest member
Malikai

### 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?

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