I have the follow set of macros that are a stopwatch with start, stop and reset buttons. The macro works perfect until you type in any cell of the spreadsheet at which time the cloc stops. Does anyone have a suggestion on how to keep the watch going even if an entry is made in the spreadsheet.
Thanks
Public StopIt1 As Boolean
Public ResetIt1 As Boolean
Public LastTime1
Private Sub CommandButton1_Click()
Dim StartTime1, FinishTime1, TotalTime1, PauseTime1
StopIt1 = False
ResetIt1 = False
If Range("e2") = 0 Then
StartTime1 = Timer
PauseTime1 = 0
LastTime1 = 0
Else
StartTime1 = 0
PauseTime1 = Timer
End If
StartIt1:
DoEvents
If StopIt1 = True Then
LastTime1 = TotalTime1
Exit Sub
Else
FinishTime1 = Timer
TotalTime1 = FinishTime1 - StartTime1 + LastTime1 - PauseTime1
TTime1 = TotalTime1 * 100
HM1 = TTime1 Mod 100
TTime1 = TTime1 \ 100
hh1 = TTime1 \ 3600
TTime1 = TTime1 Mod 3600
MM1 = TTime1 \ 60
SS1 = TTime1 Mod 60
Range("e2").Value = Format(hh1, "00") & ":" & Format(MM1, "00") & ":" & Format(SS1, "00")
If ResetIt1 = True Then
Range("e2") = Format(0, "00") & ":" & Format(0, "00") & ":" & Format(0, "00") & "." & Format(0, "00")
LastTime1 = 0
PauseTime1 = 0
End
End If
GoTo StartIt1
End If
End Sub
Private Sub CommandButton2_MouseDown(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
StopIt1 = True
End Sub
Private Sub CommandButton3_Click()
Range("e2").Value = Format(0, "00") & ":" & Format(0, "00") & ":" & Format(0, "00")
LastTime1 = 0
ResetIt1 = True
End Sub
Thanks
Public StopIt1 As Boolean
Public ResetIt1 As Boolean
Public LastTime1
Private Sub CommandButton1_Click()
Dim StartTime1, FinishTime1, TotalTime1, PauseTime1
StopIt1 = False
ResetIt1 = False
If Range("e2") = 0 Then
StartTime1 = Timer
PauseTime1 = 0
LastTime1 = 0
Else
StartTime1 = 0
PauseTime1 = Timer
End If
StartIt1:
DoEvents
If StopIt1 = True Then
LastTime1 = TotalTime1
Exit Sub
Else
FinishTime1 = Timer
TotalTime1 = FinishTime1 - StartTime1 + LastTime1 - PauseTime1
TTime1 = TotalTime1 * 100
HM1 = TTime1 Mod 100
TTime1 = TTime1 \ 100
hh1 = TTime1 \ 3600
TTime1 = TTime1 Mod 3600
MM1 = TTime1 \ 60
SS1 = TTime1 Mod 60
Range("e2").Value = Format(hh1, "00") & ":" & Format(MM1, "00") & ":" & Format(SS1, "00")
If ResetIt1 = True Then
Range("e2") = Format(0, "00") & ":" & Format(0, "00") & ":" & Format(0, "00") & "." & Format(0, "00")
LastTime1 = 0
PauseTime1 = 0
End
End If
GoTo StartIt1
End If
End Sub
Private Sub CommandButton2_MouseDown(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
StopIt1 = True
End Sub
Private Sub CommandButton3_Click()
Range("e2").Value = Format(0, "00") & ":" & Format(0, "00") & ":" & Format(0, "00")
LastTime1 = 0
ResetIt1 = True
End Sub
Last edited: