Countdown _ Timer

mmn1000

Board Regular
Joined
Mar 17, 2020
Messages
97
Office Version
  1. 2019
  2. 2013
Platform
  1. Windows
Hi,
Using the following code, a countdown is performed in sheet 1.
VBA Code:
Sub Start_Timer()
    'Check if the timer is finished and exit the macro if it is
    If Range("H7").Value = 0 Then Exit Sub
    
    'Add 1 second from the timer
    Range("H7").Value = Range("H7").Value - TimeValue("00:00:01")
    
    'Set when the macro should run again - should be the same time value
    'as the previous line.
    interval = Now + TimeValue("00:00:01")
    
    'Make this macro run again in 1 second
    Application.OnTime interval, "Start_Timer"

End Sub

How do I change this code to display a message or exit Excel after the count is complete?
 

Attachments

  • 10.png
    10.png
    5.9 KB · Views: 2
Try it

VBA Code:
Sub Start_Timer()
    'Check if the timer is finished and exit the macro if it is
    If Range("H7").Value = 0 Then
        MsgBox "The fun is over"
    Else
  
    'Add 1 second from the timer
        Range("H7").Value = Range("H7").Value - TimeValue("00:00:01")
      
        'Set when the macro should run again - should be the same time value
        'as the previous line.
        interval = Now + TimeValue("00:00:01")
      
        'Make this macro run again in 1 second
        Application.OnTime interval, "Start_Timer"
    End If
End Sub
 
Upvote 0

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top