Thank you so much for this piece of code. I am also looking for
something exactly like this. My problem is that the stop clock macro
didn't work. Any suggestions? I tried adding a button to trigger the
macro and just running the macro through the excel menu bar, and neither
worked.
OssieMac;598379 Wrote:
Hello yet again Karthi,
Your question prompted me to write some code that more fully covers
timers.
It records the start time in cell A1, then the progressive time is
displayed
in cell A2 and after the timer is stopped the total elapsed time is
displayed
in cell A3.
Unlike the times entered as text with the format function as per my
previous
post, these times can be added and subtracted etc (used in maths
equations
etc).
You start the timer from Sub StartTiming()
Dim NextTick 'Must be declared in the declarations section before any
subs.
Sub StartTiming()
Call StartClock
With ThisWorkbook.Sheets("Sheet1")
'Clear total elapsed time
.Range("A3").ClearContents
'Format the cells with time formats
.Range("A1:A3").NumberFormat = "hh:mm:ss"
'Save the start time in cell A1
.Range("A1").Value = Range("A2").Value
End With
End Sub
Sub StartClock()
With ThisWorkbook.Sheets("Sheet1")
.Range("A2") = Now()
End With
NextTick = Now + TimeValue("00:00:01")
Application.OnTime NextTick, "StartClock"
End Sub
Sub StopClock()
'Stop OnTime event.
'Returns error if already stopped and hense the on error handling.
On Error Resume Next
Application.OnTime _
EarliestTime:=NextTick, _
Procedu="StartClock", _
Schedule:=False
If Err.Number 0 Then Exit Sub
On Error GoTo 0
With ThisWorkbook.Sheets("Sheet1")
.Range("A3").Value _
= .Range("A2").Value - .Range("A1").Value
End With
End Sub
--
Regards,
OssieMac
--
apandbp
------------------------------------------------------------------------
apandbp's Profile:
http://www.thecodecage.com/forumz/member.php?u=550
View this thread:
http://www.thecodecage.com/forumz/sh...d.php?t=165832
http://www.thecodecage.com/forumz
---
news://freenews.netfront.net/ - complaints:
---