making a countdown timer

R

rbeach

below is the programming that i have created. When i enter "10" in cell A2 I
receive an error. Please assist me.

Public RunWhen As Double
Public timer_value As Integer
Public Const cRunIntervalSeconds = 1 ' 1 Second
Public Const cRunWhat = "The_Sub"

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


Sub The_Sub()

'get the current timer value
'timer_value = Range("timer").Value
timer_value = ActiveCell.FormulaR2C1

'now increase "level now" if the timer has got down to Zero
If timer_value = 0 Then Range("level_now").Value = Range("level_now").Value
+ 1

'now reduce the timer by 1, or reset to the duration if it's on Zero
If timer_value = 0 Then Range("timer").Value = Range("duration").Value Else
Range("timer").Value = timer_value - 1

'now beep in last ten seconds, first getting the new timer value
timer_value = Range("timer").Value
If timer_value > 0 And timer_value < 11 Then Beep

StartTimer

End Sub


Sub StopTimer()
On Error Resume Next
Application.OnTime earliesttime:=RunWhen, procedure:=cRunWhat,
schedule:=False
Range("timer").Value = Range("duration").Value
End Sub


Sub PauseTimer()
On Error Resume Next
Application.OnTime earliesttime:=RunWhen, procedure:=cRunWhat,
schedule:=False
End Sub


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

OssieMac

Hi rick,

I have not tested the rest of your code but the following line is incorrect,.

timer_value = ActiveCell.FormulaR2C1

Should be
timer_value = ActiveCell.Value

You use Formula like the following when you want the code to enter a formula
in a cell.
ActiveCell.FormulaR1C1 = "=10*3"
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top