See attached file, I hope that does what you need.
Code used in the sheet:
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Cells.Count = 1 And Target.Address(0, 0) = "F3" Then
If Not timerOn Then
Call Module1.StartClock
End If
End If
End Sub
Code use in module 'Module1':
Global myTime
Global timerOn As Boolean
Sub StartClock()
With ThisWorkbook.Sheets("Sheet1")
'Clear total elapsed time
If .Range("b4") = "" Then
.Range("b4") = 30
ElseIf .Range("b4") = 1 Then
lrow = .Cells(Rows.Count, "f").End(xlUp).Row
If lrow > 3 Then
.Range("f4:f" & lrow).Copy .Range("f5")
End If
.Range("f4") = .Range("f3")
.Range("b4") = 30
.Range("f3") = ""
.Range("f3").Select
Else
.Range("b4") = .Range("b4") - 1
End If
If Time >= .Range("b1") And Time <= .Range("b2") Then
timerOn = True
nextTick = Now + TimeValue("00:00:01")
myTime = nextTick
Application.OnTime nextTick, "StartClock"
Else
Call StopClock
.Range("b4").ClearContents
End If
End With
End Sub
Sub StopClock()
'Stop OnTime event.
'Returns error if already stopped and hense the on error handling.
On Error Resume Next
timerOn = False
Application.OnTime _
EarliestTime:=myTime, _
Procedure:="StartClock", _
Schedule:=False
If Err.Number > 0 Then Exit Sub
On Error GoTo 0
With ThisWorkbook.Sheets("Sheet1")
.Range("j3").Value = .Range("j1").Value - .Range("j2").Value
End With
End Sub
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Cells.Count = 1 And Target.Address(0, 0) = "F3" Then
With ThisWorkbook.Sheets("Sheet1")
If Time >= .Range("b1") And Time <= .Range("b2") Then
.Range("b4") = 30
Call StartClock
End If
End With
End If
End Sub
Regards,
Antonio
Bookmarks