Easy 5 second timer

berg891832

Well-known Member
Joined
May 2, 2002
Messages
509
Okay,

I just want an easy timer.

A user clicks a button, and after 10 seconds, a message box appears.

Basically, I am new at coding. I know just enough to be dangerous. I want to create a little timer when the user clicks the button, it starts, and they do data entry until the timer stops.

Berg
 

Some videos you may like

Excel Facts

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.

berg891832

Well-known Member
Joined
May 2, 2002
Messages
509
Well, I have to be able to do data entry on the workbook while the macro is running.

berg
 

Linus_99

Board Regular
Joined
Aug 28, 2002
Messages
145
Hi Berg,

Set up a button in the worksheet to run the following code (attached to the worksheet):

Private Sub Gonow_Click()
Dim NextTime As Date
NextTime = Now + TimeValue("00:00:10")
Application.OnTime NextTime, "Done_time"
End Sub

Set up a new module in the project with the following code:

Public Sub Done_time()
MsgBox ("Your time is up.")
End Sub

After you click on the button in the worksheet to run "Gonow", you can still enter data & edit cells until the 10 seconds runs out, when you will see the message box.

Cheers,
Linus
 

Zack Barresse

MrExcel MVP
Joined
Dec 9, 2003
Messages
10,881
Office Version
  1. 365
  2. 2010
Platform
  1. Windows
  2. Mobile
  3. Web

ADVERTISEMENT

the only way i could get this to work linus, was to take the Private out of your...
Code:
Private Sub Gonow_Click() 
Dim NextTime As Date 
NextTime = Now + TimeValue("00:00:10") 
Application.OnTime NextTime, "Done_time" 
End Sub
...routine.

other than that, works great!!
 

Linus_99

Board Regular
Joined
Aug 28, 2002
Messages
145
Good to hear that it works for you.

Then, if you want to disable the worksheet for further input or something like that, put the code after the MsgBox in the Done_time module.
 

Watch MrExcel Video

Forum statistics

Threads
1,122,518
Messages
5,596,631
Members
414,082
Latest member
sasmita

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
Top