Hi will07
I have combined both solutions here but as the Ticking Clock calculates the
wsheet each second to show the elapsed time it can have a great impact upon
other calculations which your wsheet may need to perform. This means it may
be appreciably slower to run.
Because the Ticking Clock is included here, you will notice a side effect is
it will also change the calculation for Current Time and Elapsed in B2 and C2.
For me, I would not include the Ticking Clock as it will have an impact on
the rest of the wsheet calculation but by how much will depend on what you
are doing.
Without the Ticking Clock B2 and C2 will not change until the wsheet
performs a calculation which can be as a result of your formulae or F9.
If you do not want the Ticking Clock then remove by following the comments.
hth
Geoff K
To adapt the previous solutions:
Put this in the ThisWorkbook module
Private Sub Workbook_Open()
With Sheets(1)
.Range("A1") = "Commenced"
.Range("B1") = "Current Time"
.Range("C1") = "Elapsed"
.Range("A2").NumberFormat = "dd/mm/yyyy hh:mm:ss;@"
.Range("B2").NumberFormat = "dd/mm/yyyy hh:mm:ss;@"
.Range("C2").NumberFormat = "hh:mm:ss;@"
.Range("B2").Formula = "=now()"
.Range("A2").Value = Now
.Range("C2").Formula = "=B2-A2"
End With
StartTickingClock '''<<<Remove if not required
End Sub
'''<<<Remove if not required
Private Sub Workbook_BeforeClose(Cancel As Boolean)
StopTickingClock
End Sub
************************************
Put this in a standard module (In the VBE Project Explorer click on Insert
Module)
Option Explicit
'''If Project Explorer is not revealed then from Menu goto View > Project
Explorer -
'''You will now see VBAProject(Ticking Clock.xls)
'''If there is a "+" against Modules then click to expand -
'''Right click on "Module 1" - Select "Remove Module 1" and answer "no" to
export
Public nTime As Double
Public Sub StartTickingClock()
On Error Resume Next
Application.OnTime nTime, "RunTimer", , False
On Error GoTo 0
ActiveSheet.Range("E2").Value = 0
RunTimer
End Sub
Public Sub StopTickingClock()
Application.OnTime nTime, "RunTimer", , False
End Sub
Public Sub RunTimer()
With ActiveSheet
.Range("E1") = "Elapsed"
.Range("E2").Value = .Range("E2").Value + TimeSerial(0, 0, 1)
.Range("E2").NumberFormat = "hh:mm:ss"
End With
nTime = Now + TimeSerial(0, 0, 1)
Application.OnTime nTime, "RunTimer"
End Sub
************************************
Put this in the wsheet 1 code module (Right click Sheet1 tab and select View
Code)
Option Explicit
'''''<<<Remove ALL if not required by selecting the dialog then backspace to
clear
Private Sub Worksheet_Change(ByVal Target As Range)
Const WS_RANGE As String = "1" '<== change to suit
On Error GoTo ws_exit
Application.EnableEvents = False
If Not Intersect(Target, Me.Range(WS_RANGE)) Is Nothing Then
With Target
If .Value Then
StopTickingClock
StartTickingClock
End If
End With
End If
ws_exit:
Application.EnableEvents = True
End Sub