I'd like to use a variable (X_minutes) with Application.OnTime Now + TimeValue("00:15:00")

Photomofo

Active Member
Joined
Aug 20, 2012
Messages
259
I have a code that is currently running every 15 minutes on a continuous basis. It's working fine but I'd like to have the option of running it more or less frequently. Is this possible?

Ahh... Got it. You have to format the input.

X_Minutes = "" & "00:" & X_Minutes & ":00" & ""

VBA Code:
Sub Run_Rabbit_Run()

Dim X_Minutes As String

Call EAT_ME

X_Minutes = Sheets("Index").Range("B4")

Application.OnTime Now + TimeValue(X_Minutes), "Run_Rabbit_Run"

End Sub
 

Excel Facts

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.
UNTESTED
VBA Code:
Application.OnTime Now + TimeValue("00:" & X_Minutes & ":00"), "Run_Rabbit_Run"
 
Upvote 0
Alternately, you can use the TimeSerial function...

Application.OnTime Now + TimeSerial(0, X_Minutes, 0), "Run_Rabbit_Run"
 
Upvote 0
Thanks Michael... That's essentially what I did.

Thanks Rick... That solution would clean up the code.
 
Upvote 0

Forum statistics

Threads
1,214,926
Messages
6,122,305
Members
449,079
Latest member
juggernaut24

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