Sub Timer()
Application.OnTime Now + TimeValue("00:00:01"), "StartCountDown"
End Sub
Sub StartCountDown()
Dim DownFrom As Single
DownFrom = 11
Call Timer
Range("A1").Value = Range("A1").Value + 1
UserForm1.Label1.Caption = DownFrom - Range("A1").Value
On Error Resume Next
UserForm1.Show
If Range("A1").Value = DownFrom Then
Application.OnTime Now + TimeValue("00:00:01"), "StartCountDown", schedule:=False
Range("A1") = ""
MsgBox "Time-Over"
Unload UserForm1
End If
End Sub
Hi Sahak. Don't know what am doing wrong. I tested the code on an empty userform but the form didn't show the count down on the form on test running.Hi Wilfred,
Maybe this?
VBA Code:Sub Timer() Application.OnTime Now + TimeValue("00:00:01"), "StartCountDown" End Sub Sub StartCountDown() Dim DownFrom As Single DownFrom = 11 Call Timer Range("A1").Value = Range("A1").Value + 1 UserForm1.Label1.Caption = DownFrom - Range("A1").Value On Error Resume Next UserForm1.Show If Range("A1").Value = DownFrom Then Application.OnTime Now + TimeValue("00:00:01"), "StartCountDown", schedule:=False Range("A1") = "" MsgBox "Time-Over" Unload UserForm1 End If End Sub
Yeah, I have done these earlier. Because I was testing with a new worksheet, I forgot I have not turn on the macro-setting. I later did and it works fine. Thank you very much, Sahak.You should have UserForm1 & Label1 on it & run macro "StartCountDown"