Timer causing glitches every second

B-Man

Board Regular
Joined
Dec 29, 2012
Messages
185
Office Version
  1. 2019
Platform
  1. Windows
I have setup a timer in excel using the below and its fine everything works.
my only issue is the screen glitches ever so slightly every time the macro runs(every second) not a big issue viisually but sometimes if im typing or trying to edit a formula or macro it can cause it to cancel what im doing.
is there a better way to have a timer running?
VBA Code:
Option Explicit

Dim NextTick As Date, t As Date, PreviousTimerValue As Date
Sub setKey()
    Application.OnKey "+^:", "EnterTime"
    End Sub
Sub resetKey()
    Application.OnKey "+^:"
    End Sub
Sub EnterTime()
    With ActiveCell
    .Value = Time()
    .NumberFormat = "hh:mm:ss"
        End With
    End Sub

Private Sub ExcelStopWatch()
ElectronicForm.Range("StopWatch").Value = Format(Time - t + PreviousTimerValue, "hh:mm:ss")
NextTick = Now + TimeValue("00:00:01")
Application.OnTime NextTick, "ExcelStopWatch"
End Sub
 

Excel Facts

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.
I would suggest against have the code altering a range (cell) while you are typing. If wanting to watch the seconds roll by, a modeless userform might be satisfactory.
 
Upvote 0
Thanks. I will look into that.
Can I have that open while I have another userform open?
And can I grab the current time on the timer from the user form for another macro?
 
Upvote 0
thanks @GTO finally got around to creating and testing a modeless userform and works a treat solved my issue.
 
Upvote 0

Forum statistics

Threads
1,223,950
Messages
6,175,582
Members
452,653
Latest member
craigje92

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