amerillo
New member
- Joined
- Oct 21, 2018
- Messages
- 3
- Reaction score
- 0
- Points
- 0
- Excel Version(s)
- 2016
Hello all,
Just wondering if someone can help me with what I think is a very small coding problem that I can't seem to figure out for myself! VBA is certainly not my forte, but I have managed to come up with the attached code for a count-up timer. Currently the timer continues indefinitely, however, I would like it to stop at 65 seconds. Could someone please tell me what coding line(s) I would need to add to make this happen? I have tried various work arounds, and they have failed to do the trick! I'm guessing it is some kind of "Do Until" loop that I need to enter?
Many thanks!
AM
Code:
I have this code written into a module:
Just wondering if someone can help me with what I think is a very small coding problem that I can't seem to figure out for myself! VBA is certainly not my forte, but I have managed to come up with the attached code for a count-up timer. Currently the timer continues indefinitely, however, I would like it to stop at 65 seconds. Could someone please tell me what coding line(s) I would need to add to make this happen? I have tried various work arounds, and they have failed to do the trick! I'm guessing it is some kind of "Do Until" loop that I need to enter?
Many thanks!
AM
Code:
I have this code written into a module:
Code:
Dim CountDown As Date
Dim count As Range
Sub RunTime()
CountDown = Now + TimeValue("00:00:01")
If count.Value >= TimeValue("00:00:01") Then
Application.OnTime CountDown, "Counter"
Else
Call DisableCount
End If
End Sub
Sub Counter()
Dim ws As Worksheet
Set ws = ThisWorkbook.Worksheets("Data1")
Set count = ws.Range("b11")
count.Value = count.Value + TimeValue("00:00:01")
Call RunTime
End Sub
Sub DisableCount()
On Error Resume Next
Application.OnTime EarliestTime:=CountDown, Procedure:="Counter", Schedule:=False
End Sub
Sub Reset()
Dim ws As Worksheet
Set ws = ThisWorkbook.Worksheets("Data1")
Set count = ws.Range("b11")
On Error Resume Next
Application.OnTime EarliestTime:=CountDown, Procedure:="Counter", Schedule:=False
count.Value = TimeValue("00:00:00")
End Sub