![]() |
making a countdown timer
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, procedu=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, procedu=cRunWhat, schedule:=False Range("timer").Value = Range("duration").Value End Sub Sub PauseTimer() On Error Resume Next Application.OnTime earliesttime:=RunWhen, procedu=cRunWhat, schedule:=False End Sub Sub ResumeTimer() RunWhen = Now + TimeSerial(0, 0, cRunIntervalSeconds) Application.OnTime earliesttime:=RunWhen, procedu=cRunWhat, schedule:=True End Sub -- Rick |
making a countdown timer
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" -- Regards, OssieMac |
All times are GMT +1. The time now is 05:03 AM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com