running clock in hh:mm format

robertvdb

Active Member
Joined
Jan 10, 2021
Messages
342
Office Version
  1. 2016
Platform
  1. Windows
I have an issue with a running clock in one of my sheets.

The clock runs in hh:mm format, because I don't need/want the seconds to be displayed.
The clock is initiated upon activation of the sheet.
Code as below.

Now he thing is, when I activate the sheet at say 09:39:30, then the cell shows 09:39. Which is correct.
However, the cell only changes to 09:40 one minute after activation, which is at 09:40:30. Which is 30 seconds too late.

How to solve this ?

VBA Code:
Private Sub Worksheet_Activate()
    Application.OnTime Now + TimeSerial(0, 1, 0), "UpdateTimer1"
End Sub



VBA Code:
Public Sub UpdateTimer1()

ActiveSheet.Cells(1, 2).Value = Format$(Now, "mm/dd/yyyy")
ActiveSheet.Cells(2, 2).Value = Format$(Now, "hh:mm")
Application.OnTime Now + TimeSerial(0, 1, 0), "UpdateTimer1"

End Sub
 

Attachments

  • clock.png
    clock.png
    14.4 KB · Views: 5

Excel Facts

What did Pito Salas invent?
Pito Salas, working for Lotus, popularized what would become to be pivot tables. It was released as Lotus Improv in 1989.
Hi, you could try changing your Worksheet_Activate() sub to..

VBA Code:
With Application
    .OnTime .Ceiling(Now, "00:01:00"), "UpdateTimer1"
End With
 
Upvote 0
Solution

Forum statistics

Threads
1,226,112
Messages
6,189,041
Members
453,521
Latest member
Chris_Hed

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