Scheduling a Macro to Run at 6 Specific Times Throughout the Day

waly01

New Member
Joined
Aug 11, 2009
Messages
29
Hi,
I'd like to apologize in advance if the following question seems rudimentary as I'm very new to VBA. However, i've written a macro that basically just pastes a row as values for every sheet in my workbook.
I would like for this to run automatically at 6 specific times throughout the day: 700, 900, 1100,1130,1400,1430. Mon-Fri only.
In doing research, i know im supposed to use the Application.Ontime functionality however, i've been unable to get this to run correctly.
Any help would be greatly appreciated. Here is my code:


Code:
<code class="s1s4008e-7 hGYywx">Sub PopulateData()

Dim WS_Count As Integer
Dim I As Integer

WS_Count = ActiveWorkbook.Worksheets.Count
Application.DisplayAlerts = False
Application.ScreenUpdating = False

For I = 1 To WS_Count

Sheets("Crude").Range("Date_Time2").Copy

ActiveWorkbook.Worksheets(I).Activate

Cells.Find(What:="Date", After:=ActiveCell, LookIn:=xlFormulas, LookAt _
:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:= _
False, SearchFormat:=False).End(xlDown).Offset(1, 0).Activate
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False

Range(Selection, Selection.End(xlToRight)).Copy
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Next I

ActiveWorkbook.Worksheets("Crude").Activate
ActiveWorkbook.Save
Application.DisplayAlerts = True
Application.ScreenUpdating = True
End Sub</code>


I've tried the following without any luck:

Code:
<code class="s1s4008e-7 hGYywx">Private Sub Workbook_Open()
    Application.OnTime TimeValue("07:00:00"), "PopulateData"
    Application.OnTime TimeValue("09:00:00"), "PopulateData"
    Application.OnTime TimeValue("11:00:00"), "PopulateData"
    Application.OnTime TimeValue("11:30:00"), "PopulateData"
    Application.OnTime TimeValue("14:00:00"), "PopulateData"
    Application.OnTime TimeValue("14:30:00"), "PopulateData"
End Sub</code>

screenshot of my VBA: https://imgur.com/a/9T1M9So
 

Excel Facts

How to find 2nd largest value in a column?
MAX finds the largest value. =LARGE(A:A,2) will find the second largest. =SMALL(A:A,3) will find the third smallest

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

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