sspatriots
Well-known Member
- Joined
- Nov 22, 2011
- Messages
- 585
- Office Version
- 365
- Platform
- Windows
Good morning,
I am using this timer I found online to track time spent on different jobs task throughout the day. Seems to start and stop ok during the day. I minimized the screen over night and came in this morning and opened it up and the timer was still running (which is what I was testing out). However, as soon as I selected the stop button, the time went from 15 hours back to 8 hours. If I select the "Start" button again it will resume from the 8 hour number that it when back to. The "Reset" button is set up to copy the total time when ready to clear the field back to all zeroes and allow the user to put that value in a cell in a column that tallies the total time on the job. Also, I'm attaching a screenshot of an error message that another user got this morning when he closed the file and reopened it. Just looking to clean this up to avoid the errors. Seems to work fine as long as the screen is open during the day and stays open. Any help on this would be much appreciated.
Thanks, SS
I am using this timer I found online to track time spent on different jobs task throughout the day. Seems to start and stop ok during the day. I minimized the screen over night and came in this morning and opened it up and the timer was still running (which is what I was testing out). However, as soon as I selected the stop button, the time went from 15 hours back to 8 hours. If I select the "Start" button again it will resume from the 8 hour number that it when back to. The "Reset" button is set up to copy the total time when ready to clear the field back to all zeroes and allow the user to put that value in a cell in a column that tallies the total time on the job. Also, I'm attaching a screenshot of an error message that another user got this morning when he closed the file and reopened it. Just looking to clean this up to avoid the errors. Seems to work fine as long as the screen is open during the day and stays open. Any help on this would be much appreciated.
Thanks, SS
VBA Code:
Option Explicit
' Written by Philip Treacy, My Online Training Hub
' https://www.myonlinetraininghub.com/timer-stopwatch-excel-vba
Sub StartTimer()
Dim Start As Single, RunTime As Single, CurrentlyElapsed As Single
Dim ElapsedTime As String
'Set the control cell to 0 and make it green
Range("B1").Value = 0
Range("C4").Interior.Color = 13561798 'Light Green
Range("C4").Font.Color = 24832 'Dark Green
'If Range("D1").Value <> 0 Then CurrentlyElapsed = Range("D1").Value
Start = Timer ' Set start time.
Debug.Print Start
Do While Range("B1").Value = 0
DoEvents ' Yield to other processes.
RunTime = Timer ' current elapsed time
CurrentlyElapsed = RunTime - Start + Range("D1").Value
ElapsedTime = Format(CurrentlyElapsed / 86400, "hh:mm:ss")
' ElapsedTime = Format(CurrentlyElapsed / 86400, "hh:mm")
'Display currently elapsed time in C4
Range("C4").Value = ElapsedTime
Application.StatusBar = ElapsedTime
Loop
Range("C4").Value = ElapsedTime
Range("C4").Interior.Color = 13551615 'light Red
Range("C4").Font.Color = 393372 'Dark Red
Range("D1").Value = CurrentlyElapsed
Application.StatusBar = False
End Sub
Sub StopTimer()
'Set the control cell to 1
Range("B1").Value = 1
End Sub
Sub ResetTimer()
Dim myRange As Range
Dim CopyRange As Range
Set CopyRange = Range("C4")
On Error Resume Next
Set myRange = Application.InputBox(Prompt:="Select Cell you want to capture your total time in.", Title:="Format Titles", Type:=8)
If myRange Is Nothing Then
MsgBox "No selection made", vbCritical, "Input required"
Exit Sub
End If
myRange.Value = CopyRange.Value
If Range("B1").Value > 0 Then
'Set the control cell to 1
Range("C4").Value = Format(0, "hh:mm:ss")
' Range("C4").Value = Format(0, "hh:mm")
Range("C4").Interior.Color = 10284031 'light Gold
Range("C4").Font.Color = 22428 'Dark Brown
Range("D1").Value = 0
End If
End Sub
[ATTACH type="full"]97192[/ATTACH][ATTACH type="full"]97193[/ATTACH]