RE: Expressing Application.onTime("00:00:10") as a variable...

chazrab

Well-known Member
Joined
Oct 21, 2006
Messages
917
Office Version
  1. 365
Platform
  1. Windows
RE: Expressing Application.onTime("00:00:10") as a variable...

I just want to be able to vary the time to display a MsgBox using a variable
from a cell value on a sheet using Application.onTime("h:m:s"), where h, m and t are variables In the title, a variable evaluates to 10 seconds. Would anyone know how to do that?
Thx for anyone's help
cr
 

Excel Facts

Do you hate GETPIVOTDATA?
Prevent GETPIVOTDATA. Select inside a PivotTable. In the Analyze tab of the ribbon, open the dropown next to Options and turn it off
Re: Expressing Application.onTime("00:00:10") as a variable...

You can use a varible for the time like this.

Code:
Sub t()
[COLOR=#ff0000]Dim tm As Date
tm = Range("B2").Value
[/COLOR]Application.OnTime ([COLOR=#ff0000]tm[/COLOR]), "tt"
End Sub


Sub tt()
MsgBox "It Worked"
End Sub

The value in B2 would be entered in 00:00:00 format.
 
Last edited:
Upvote 0
Re: Expressing Application.onTime("00:00:10") as a variable...

You can use a varible for the time like this.

Code:
Sub t()
[COLOR=#ff0000]Dim tm As Date
tm = Range("B2").Value
[/COLOR]Application.OnTime ([COLOR=#ff0000]tm[/COLOR]), "tt"
End Sub


Sub tt()
MsgBox "It Worked"
End Sub

The value in B2 would be entered in 00:00:00 format.

I'm putting, 1, 2 3, etc. for hours in cell B2. Nothing happens. I just want to have the MsgBox appear whenever I want based on the value in B2. What am I doing wrong ? The cell is formated as number with no decimal places. Thx for your help. cr
 
Upvote 0
Re: Expressing Application.onTime("00:00:10") as a variable...

Apparently you did not read the last line in post #2 . The value in cell B2 must be formatted as time, eg: 00:00:00. So if you want 1 hour from current time then
Code:
Time + 01:00:00
would go in cell B2, If you want a specific time like 9:45 PM then cell B2 would be
Code:
21:45:00
The tm variable must equate to the "00:00:00" format for the code to work.
 
Last edited:
Upvote 0

Forum statistics

Threads
1,223,888
Messages
6,175,219
Members
452,619
Latest member
Shiv1198

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