Could someone offer an insight into why this crashes my excel, i cant seem to work it out. Im trying to learn VBA and need some advice.
sub timer()
dim second
second = 1.15740740740741e-05
'this is the amount excel counts as a second
line1:
application.wait "00:00:01"
Range("a1").value = Range("a1").value - second
if not range("D2").value = 0 then
Goto line1
else
Msgbox("Countdown ended")
End if
end sub
This is the best way to do this.
Try to use this code below:
I'm sure you're not timing space shuttle launches or anything that critical. But if you want to make sure your countdown doesn't take longer than 30 seconds, you can use the Timer function. Here's an example.
If it just about count down every second, I guess there is another option to add a Timer functionality to Excel. Try searching for Application.OnTime function in Excel that enables us to have Timer in Excel. Related Article that explains how to add timer in Excel and make a macro run during that scheduled interval.