Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Stopwatch/Clock

I want to display the time in a worksheet but want it to update automatically like a clock

It is to be used like a clock at a football game - any ideas

I have done it by using a macro to paste the time the game starts in a cell and then use Now()-start time to give elapsed time

I then have a macro to f9

I'm sure it can be done automaticly every second but don't know how

Any ideas?
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 218
Default Stopwatch/Clock

Check out John Walkenbauch's utility:

http://j-walk.com/ss/excel/files/clockchart.htm

Regards,
Greg


-----Original Message-----
I want to display the time in a worksheet but want it to

update automatically like a clock.

It is to be used like a clock at a football game - any

ideas.

I have done it by using a macro to paste the time the

game starts in a cell and then use Now()-start time to
give elapsed time.

I then have a macro to f9

I'm sure it can be done automaticly every second but

don't know how.

Any ideas?
.

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Stopwatch/Clock

Thanks Greg - Nice piece of code

Now I just have to understand it so I can intergrate it into my project.
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 18
Default Stopwatch/Clock

To start you off, try something like:

Option Explicit
Dim ClockRunning As Boolean

Sub StartClock()
ClockRunning = True
ControlClock
End Sub

Sub StopClock()
ClockRunning = False
End Sub

Sub ControlClock()
If ClockRunning = True Then
Range("A1") = Format(Now, "hh:mm:ss")
Application.OnTime Now + TimeValue("00:00:01"), "ControlClock"
End If
End Sub


To start the clock, just run the StartClock macro, and the StopClock
macro to stop the code.

You can expand the functionality from here to do all sorts of funky things

Hope this helps.

Scott

Easty wrote:

I want to display the time in a worksheet but want it to update automatically like a clock.

It is to be used like a clock at a football game - any ideas.

I have done it by using a macro to paste the time the game starts in a cell and then use Now()-start time to give elapsed time.

I then have a macro to f9

I'm sure it can be done automaticly every second but don't know how.

Any ideas?


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 18
Default Stopwatch/Clock

..... and for the elapsed time, perhaps something like this?

Option Explicit
Dim ClockRunning As Boolean
Dim StartTime

Sub StartClock()
ClockRunning = True
StartTime = Now
ControlClock
End Sub

Sub StopClock()
ClockRunning = False
End Sub

Sub ControlClock()
Dim ElapsedHours, ElapsedMinutes, ElapsedSeconds

ElapsedHours = "0"
ElapsedMinutes = "00"

If ClockRunning = True Then
ElapsedSeconds = DateDiff("s", StartTime, Now())
If ElapsedSeconds = 3600 Then
ElapsedHours = Int(ElapsedSeconds / 3600)
ElapsedSeconds = ElapsedSeconds - ElapsedHours * 3600
End If
If ElapsedSeconds = 60 Then
ElapsedMinutes = Int(ElapsedSeconds / 60)
ElapsedSeconds = ElapsedSeconds - ElapsedMinutes * 60
If ElapsedMinutes < 10 Then ElapsedMinutes = "0" & ElapsedMinutes
End If
If ElapsedSeconds < 10 Then ElapsedSeconds = "0" & ElapsedSeconds

Range("A1") = ElapsedHours & ":" & ElapsedMinutes & ":" & ElapsedSeconds
Application.OnTime Now + TimeValue("00:00:01"), "ControlClock"
End If

End Sub


Easty wrote:

I want to display the time in a worksheet but want it to update automatically like a clock.

It is to be used like a clock at a football game - any ideas.

I have done it by using a macro to paste the time the game starts in a cell and then use Now()-start time to give elapsed time.

I then have a macro to f9

I'm sure it can be done automaticly every second but don't know how.

Any ideas?




  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 107
Default Stopwatch/Clock

Or perhaps a little shorter:

Dim ClockRunning As Boolean
Dim StartTime

Sub StartClock()
ClockRunning = True
StartTime = Now
Range("a1").NumberFormat = "[hh].mm.ss"
ControlClock
End Sub

Sub StopClock()
ClockRunning = False
End Sub

Sub ControlClock()
If ClockRunning = True Then
Range("a1").Value = Now - StartTime
Application.OnTime Now + TimeValue("00:00:01"), "ControlClock"
End If
End Sub



SmilingPolitely wrote:
.... and for the elapsed time, perhaps something like this?

Option Explicit
Dim ClockRunning As Boolean
Dim StartTime

Sub StartClock()
ClockRunning = True
StartTime = Now
ControlClock
End Sub

Sub StopClock()
ClockRunning = False
End Sub

Sub ControlClock()
Dim ElapsedHours, ElapsedMinutes, ElapsedSeconds

ElapsedHours = "0"
ElapsedMinutes = "00"

If ClockRunning = True Then
ElapsedSeconds = DateDiff("s", StartTime, Now())
If ElapsedSeconds = 3600 Then
ElapsedHours = Int(ElapsedSeconds / 3600)
ElapsedSeconds = ElapsedSeconds - ElapsedHours * 3600
End If
If ElapsedSeconds = 60 Then
ElapsedMinutes = Int(ElapsedSeconds / 60)
ElapsedSeconds = ElapsedSeconds - ElapsedMinutes * 60
If ElapsedMinutes < 10 Then ElapsedMinutes = "0" & ElapsedMinutes
End If
If ElapsedSeconds < 10 Then ElapsedSeconds = "0" & ElapsedSeconds

Range("A1") = ElapsedHours & ":" & ElapsedMinutes & ":" & ElapsedSeconds
Application.OnTime Now + TimeValue("00:00:01"), "ControlClock"
End If

End Sub


Easty wrote:

I want to display the time in a worksheet but want it to update
automatically like a clock.

It is to be used like a clock at a football game - any ideas.

I have done it by using a macro to paste the time the game starts in a
cell and then use Now()-start time to give elapsed time.

I then have a macro to f9
I'm sure it can be done automaticly every second but don't know how.

Any ideas?




  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default Stopwatch/Clock

Easty,

Here is a non-graphic approach which can be used as a countdown timer, a
clock, in a cell or the status bar.

http://tinyurl.com/2dua6

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

"Easty" wrote in message
...
I want to display the time in a worksheet but want it to update

automatically like a clock.

It is to be used like a clock at a football game - any ideas.

I have done it by using a macro to paste the time the game starts in a

cell and then use Now()-start time to give elapsed time.

I then have a macro to f9

I'm sure it can be done automaticly every second but don't know how.

Any ideas?



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Stopwatch Bob Excel Discussion (Misc queries) 5 February 3rd 09 01:32 AM
Incremental time values based upon clock in and clock out times saltnsnails Excel Discussion (Misc queries) 8 January 13th 09 08:11 PM
How do I calculate time in excel (clock in and clock out chad Excel Discussion (Misc queries) 3 January 7th 08 10:09 PM
Change EXCEL Clock to Standard Clock or Military Time YoMarie Excel Worksheet Functions 4 April 29th 07 08:39 PM
Start Clock/Stop Clock abfabrob Excel Discussion (Misc queries) 9 June 28th 05 04:26 PM


All times are GMT +1. The time now is 05:09 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"