Application.Ontime Date and Time

becklog

New Member
Joined
Dec 26, 2016
Messages
38
Hi,

Is there a way for me to improve the code below? There are times that I only need to run the command (Time1) 2 or 3 times. Leaving Row A4 and A5 without any date and time value will cause the macro to go to the debug option and the only way for me to proceed is to delete the last 2 lines of the command. What I want to achieve is for the command below to run even there are some cells that does not have any date or time value. Thanks in advance!


"Time1" = a macro command
Column A = Date
Column B = Time


Sub OnTime()

Application.OnTime DateValue(Range("A1").Text) + TimeValue(Range("B1").Text), "Time1"
Application.OnTime DateValue(Range("A2").Text) + TimeValue(Range("B2").Text), "Time1"
Application.OnTime DateValue(Range("A3").Text) + TimeValue(Range("B3").Text), "Time1"
Application.OnTime DateValue(Range("A4").Text) + TimeValue(Range("B4").Text), "Time1"
Application.OnTime DateValue(Range("A5").Text) + TimeValue(Range("B5").Text), "Time1"

End Sub
 

Excel Facts

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".
use this

if(Range("A4").Text)<>"" then
Application.OnTime DateValue(Range("A4").Text) + TimeValue(Range("B4").Text), "Time1"
End if

Above code will skip if A4 is empty, you can do this for A5 similarly.
 
Upvote 0

Forum statistics

Threads
1,214,641
Messages
6,120,693
Members
448,979
Latest member
DET4492

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