Computing.Net > Forums > Office Software > time counter

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

time counter

Reply to Message Icon

Name: mherber2
Date: June 29, 2008 at 09:36:22 Pacific
OS: unknown
CPU/Ram: unknown
Product: unknown
Comment:

im trying to create a timer in excel using vba but im not getting any where...

im looking for a timer that will be on the worksheet that has buttons to start stop pause and reset. the timer i want to show in a text box on the worksheet...also when the workbook is closed i need the value of where the timer is at to be saved that way when i can pick up where i left off...

i already have the buttons and text box on my worksheet...i just lacking the code to make it work...can anyone help me please?



Sponsored Link
Ads by Google

Response Number 1
Name: AlwaysWillingToLearn
Date: July 1, 2008 at 04:21:04 Pacific
Reply:

Here is how ti mplement a timer in Ecxel

create a button on sheet1 and paste the following code in it click event

Private Sub CommandButton1_Click()
StartTimer
End Sub


Now insert a modual and copy paste the following into it.

Public RunWhen As Double
Public Const cRunIntervalSeconds = 1
Public Const cRunWhat = "The_Sub"

Sub StartTimer()

Application.ScreenUpdating = False
RunWhen = Now + TimeSerial(0, 0, cRunIntervalSeconds)
Application.OnTime earliesttime:=RunWhen, procedure:=cRunWhat, _
schedule:=True
End Sub

Sub The_Sub()

Sheet1.Range("A1").Value = Sheet1.Range("A1").Value + 1
StartTimer
End Sub


0

Response Number 2
Name: mherber2
Date: July 3, 2008 at 09:05:27 Pacific
Reply:

ok great that will work but now how can i stop it and pick back up where it left off? it also needs to count min and sec not just sec...

i added this to the sheet

Private Sub cmdReset_Click()
Sheet3.Timer.Caption = 0
End Sub

this works for my reset i just need a stop...


0

Response Number 3
Name: mherber2
Date: July 3, 2008 at 15:00:16 Pacific
Reply:

ok all i have a start stop and reset... thank you Always...i modified your code slightly...heres what i have:

in my Module:

Public RunWhen As Double
Public Const cRunIntervalSeconds = 1
Public Const cRunWhat = "The_Sub"

Sub StartTimer()

Application.ScreenUpdating = False
RunWhen = Now + TimeSerial(0, 0, cRunIntervalSeconds)
Application.OnTime earliesttime:=RunWhen, procedure:=cRunWhat, _
schedule:=True
End Sub

Sub The_Sub()
Sheet3.Timer.Caption = Sheet3.Timer.Caption + 1
If Sheet1.cmdStart.Enabled = False Then _
StartTimer
End Sub

on my sheet1:
Private Sub cmdReset_Click()
Timer.Caption = 0
cmdStart.Enabled = True
cmdStop.Enabled = False
cmdReset.Enabled = True
End Sub

Private Sub cmdStart_Click()
cmdStart.Enabled = False
cmdStop.Enabled = True
cmdReset.Enabled = False
StartTimer
End Sub

Private Sub cmdStop_Click()
cmdStart.Enabled = True
cmdStop.Enabled = False
cmdReset.Enabled = True
End Sub


and this all works..the only problem is is that it is in seconds...how can i get min and secs?


0

Response Number 4
Name: AlwaysWillingToLearn
Date: July 8, 2008 at 03:06:20 Pacific
Reply:

you can use an if statement to say if sheet3.timer.caption <= 60 then "A3" .value= "A3".value +1 that will then capture the minutes. then the seconds will have to reset to 0 again. Ill try to have a go at it and send a peice of code back to you.


0

Response Number 5
Name: mherber2
Date: July 11, 2008 at 08:32:14 Pacific
Reply:

Alrighty let me know if you come up with anything please


0

Related Posts

See More



Sponsored Link
Ads by Google
Reply to Message Icon

scheduling shifts Best Office Suite



Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Office Software Forum Home


Sponsored links

Ads by Google


Results for: time counter

Need to develop an ongoing monthly time clock www.computing.net/answers/office/need-to-develop-an-ongoing-monthly-time-clock/8861.html

Calculating time for schedules www.computing.net/answers/office/calculating-time-for-schedules/4255.html

Excel time/date formatting www.computing.net/answers/office/excel-timedate-formatting/1303.html