Countdown Timer Excel VBA - Code crashed excel

后端 未结 3 362
渐次进展
渐次进展 2021-01-28 14:16

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         


        
3条回答
  •  爱一瞬间的悲伤
    2021-01-28 14:36

    This is the best way to do this.

    Try to use this code below:

    Sub Countup() 
    Dim CountDown As Date 
    CountDown = Now + TimeValue("00:00:01") 
    Application.OnTime CountDown, "Realcount" 
    End Sub
    
    Sub Realcount() 'Run this to count down your cell value
    Dim count As Range 
    Set count = [E1] 'Put the range that you want to count down
    count.Value = count.Value - TimeSerial(0, 0, 1) 
    If count <= 0 Then 
    MsgBox "Countdown complete." 
    Exit Sub 
    End If 
    Call Countup 
    End Sub
    

提交回复
热议问题