Do Until Loop query

shumba

Board Regular
Joined
Oct 5, 2010
Messages
168
Good Afternoon,


Please will someone advise me on the correct syntax for a Do Until Loop to a specific time. The procedure below produces a compile error.

Code:
Sub Phase2()
      Dim i  As  Integer
      'Application.ScreenUpdating = False
      'Workbooks("Data Collection Template Ver 2.xlsm").Activate
      
      Do Until Application.OnTime TimeValue("07:02:00"),
      Sheets("Data Collection and Compilation").Select
      Range("h2:h3006").Copy
      Selection.Offset(-1, 0).Value = Now
      Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
          :=False, Transpose:=False
      Selection.Offset(1, 0).Select
      Selection.FormulaR1C1 = "=AVERAGE(R[-1]C[-5]:R[-1]C)"
      
      For i = 1 To 1502
      Selection.Offset(2, 0).Select
      Selection.FormulaR1C1 = "=AVERAGE(R[-1]C[-5]:R[-1]C)"
      Next i
      Selection.Offset(-3005, 1).Select
      Loop
  End Sub
Any help will be much appreciated.

Rob.
 

Excel Facts

Control Word Wrap
Press Alt+Enter to move to a new row in a cell. Lets you control where the words wrap.
This seems to work for me--

Change this:
Code:
Do Until Application.OnTime TimeValue("07:02:00"),

To this:
Code:
Do Until Format(Now, "hh:mm:ss") >= "07:02:00"

And give it a shot
 
Upvote 0
Thanks for your help. I will give it a go as soon as I start work this morning.

Regards,

Rob.
 
Upvote 0

Forum statistics

Threads
1,224,599
Messages
6,179,828
Members
452,946
Latest member
JoseDavid

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