当数字达到零时,多个倒计时器发生错误

时间:2017-06-13 20:03:26

标签: excel vba excel-vba

我正在尝试学习倒计时宏,我从Jerry Beaucaire的网站上下载了这个文件。谢谢杰瑞! 我调整了一下。我没有将值从0计数到无限数,而是将其从我在C列中键入的数字倒数到零。但是当数字达到零时会发生错误。我该如何解决这个错误?如何在A列中创建一个按钮当数字达到零时切换回“DOWN”?

Dim CountDown As Date

Sub Timer()
DisableTimer
CountDown = Now + TimeValue("00:00:01")
Application.OnTime CountDown, "Reset"
End Sub

Sub Reset()
Dim Counter As Range
Application.ScreenUpdating = False
Application.EnableEvents = False

If Evaluate("COUNT(B2:B5)") = 0 Then
    Call DisableTimer
Else
    For Each Counter In ThisWorkbook.Sheets("Sheet1").Range("B2:B5")
        If Not IsEmpty(Counter) Then Counter = Counter - TimeValue("00:00:01")
    Next Counter
    Call Timer
End If

Application.ScreenUpdating = True
Application.EnableEvents = True
End Sub

Sub DisableTimer()
On Error Resume Next

Application.OnTime EarliestTime:=CountDown, Procedure:="Reset", Schedule:=False

End Sub

Source File

1 个答案:

答案 0 :(得分:0)

替换它:

If Not IsEmpty(Counter) Then Counter = Counter - TimeValue("00:00:01")

有了这个:

If Counter > TimeValue("00:00:01") Then
  Counter = Counter - TimeValue("00:00:01")
Else
  Counter = ""
End If