Hi Everyone, could someone please assist me.
Following code:
What I have noticed is when you press pause JUST before the timer wants to add another second. It crashes and gives the error in the topic.
How can I fix this? Everything else works well. It just happens now and then.
Following code:
VBA Code:
Option Explicit
Public sTimer As Boolean
Public sTimer2 As Boolean
Public sTimer3 As Boolean
Public sTimer4 As Boolean
Public sTimer5 As Boolean
Public sTimer6 As Boolean
Public sTimer7 As Boolean
Public sTimer8 As Boolean
Public sTimer9 As Boolean
Public sTimer10 As Boolean
Public wsSheet1 As Worksheet, wsTimeSummary As Worksheet
Sub Start_Timer()
Application.OnTime Now + TimeValue("00:00:01"), "IncreamentTimer"
End Sub
Sub IncreamentTimer()
If ThisWorkbook.Sheets("Sheet1").Range("K9").Value = "" Then ThisWorkbook.Sheets("Sheet1").Range("K9").Value = TimeValue(Now)
If ThisWorkbook.Sheets("Sheet1").Range("K8").Value = "" Then ThisWorkbook.Sheets("Sheet1").Range("K8").Value = TimeValue(Now)
ThisWorkbook.Sheets("Sheet1").Range("K8").Value = ThisWorkbook.Sheets("Sheet1").Range("K8").Value + TimeValue("00:00:01")
If ThisWorkbook.Sheets("Sheet1").Range("J8").Value = "" Then ThisWorkbook.Sheets("Sheet1").Range("J8").Value = "Timer ON"
ThisWorkbook.Sheets("Sheet1").Range("J9").Value = "Timer Start Time"
ThisWorkbook.Sheets("Sheet1").Range("J8").Font.Color = vbGreen
sTimer = True
Start_Timer
End Sub
Sub PauseResume_Timer()
If ThisWorkbook.Sheets("Sheet1").Range("K9").Value <> "" Then
If sTimer = True Then
sTimer = False
Application.OnTime Now + TimeValue("00:00:01"), "IncreamentTimer", schedule:=False
ThisWorkbook.Sheets("Sheet1").Range("J8").Value = "Timer Paused"
ThisWorkbook.Sheets("Sheet1").Range("J8").Font.Color = vbRed
Else
Application.OnTime Now + TimeValue("00:00:01"), "IncreamentTimer"
ThisWorkbook.Sheets("Sheet1").Range("J8").Value = "Timer Resumed"
ThisWorkbook.Sheets("Sheet1").Range("J8").Font.Color = vbGreen
End If
Else
MsgBox "You can only click Pause/Resume button when Timer is On.", vbExclamation, "Timer Off!"
End If
End Sub
Sub Stop_Timer()
With ThisWorkbook
Set wsSheet1 = .Worksheets("Sheet1")
Set wsTimeSummary = .Worksheets("Time Summary")
End With
On Error Resume Next
Application.OnTime Now + TimeValue("00:00:01"), "IncreamentTimer", schedule:=False
If Err = 0 Then
With wsSheet1
.Range("L9").Value = Format(.Range("K8").Value - .Range("K9").Value, "hh:mm:ss")
.Range("J8").Value = "Timer OFF"
.Range("J8").Font.Color = vbBlack
End With
With wsTimeSummary
.Range("D12").Copy
.Range("E12").PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, _
SkipBlanks:=False, Transpose:=False
End With
Application.CutCopyMode = False
Else
MsgBox "Timer Is currently OFF.", vbExclamation, "Timer Is OFF!"
End If
End Sub
Sub Reset_Timer()
ThisWorkbook.Sheets("Sheet1").Range("K8").Value = ""
ThisWorkbook.Sheets("Sheet1").Range("K9").Value = ""
ThisWorkbook.Sheets("Sheet1").Range("J8").Value = ""
ThisWorkbook.Sheets("Sheet1").Range("J9").Value = ""
ThisWorkbook.Sheets("Sheet1").Range("L9").Value = ""
End Sub
What I have noticed is when you press pause JUST before the timer wants to add another second. It crashes and gives the error in the topic.
How can I fix this? Everything else works well. It just happens now and then.