Hello Lovely Excel Experts!! I am here again for your vast wisdom.
I have coded a timer (using a userform) it works beautifully I am just looking to add a feature if possible. Userforms as far as I know don't save data once the file is closed so what I need to figure out is how to allow for a timer "pause" and "continue" from the same place even after the file has been closed and re-opened. I am happy to have the data stored somewhere on the sheet, just curious if this is possible. See code below and screengrab of the timer userform & sheet for visuals
UserForm1
_________________________________
Thanks a MILLION in advance!!
I have coded a timer (using a userform) it works beautifully I am just looking to add a feature if possible. Userforms as far as I know don't save data once the file is closed so what I need to figure out is how to allow for a timer "pause" and "continue" from the same place even after the file has been closed and re-opened. I am happy to have the data stored somewhere on the sheet, just curious if this is possible. See code below and screengrab of the timer userform & sheet for visuals
UserForm1
VBA Code:
Option Explicit
Dim CmdStop As Boolean
Dim Paused As Boolean
Dim Start
Dim TimerValue As Date
Dim pausedTime As Date
Sub btnStart_Click()
btnPause.Enabled = True
CmdStop = False
Paused = False
Start = Now() ' Set start time.
btnPause.Enabled = True
btnStop.Enabled = True
btnReset.Enabled = False
Do While CmdStop = False
If Not Paused Then
TimerValue = Now() - Start - pausedTime
Else
pausedTime = Now() - TimerValue - Start
End If
TimerReadOut = Format(TimerValue, "h:mm:ss")
DoEvents ' Yield to other processes.
Loop
End Sub
Sub btnPause_Click()
If btnPause.Caption = "Pause" Then
Paused = True
btnPause.Caption = "Continue"
Else
Paused = False
btnPause.Caption = "Pause"
End If
UserForm1.Hide
End Sub
Sub BtnReset_Click()
TimerReadOut = "0:00:00"
btnStop.Enabled = False
End Sub
Sub BtnStop_Click()
btnPause.Enabled = False
btnReset.Enabled = True
btnStop.Enabled = False
CmdStop = True
Sheet1.Range("M8").Value = TimerReadOut.Value
If TimerReadOut.Value = "" Then Sheet1.Range("M9").Value = ""
UserForm1.Hide
End Sub
Private Sub BtnReset_MouseUp(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
If Shift = 0 Then
Range("N8") = Range("N8") + 1
Else: Range("N8") = Range("N8") - 1
End If
End Sub
Thanks a MILLION in advance!!
Last edited by a moderator: