Do Until Loop for time

shumba

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


I would like to loop the procedure below for one minute. I have used a Do Until Loop but this is not working.

Please will someone show me where I am going wrong.



Code:
Public Const cRunForTime = "00:01:00"
  

Sub Phase1()
     Sheets("Data Collection and Compilation").Select 
      Do Until TimeValue(cRunForTime)
      Selection.Offset(-1, 0).Value = Now
      Selection.NumberFormat = "0.00%"
      Range("h2:h100").Copy
      Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
          :=False, Transpose:=False
      Selection.Offset(0, 1).Select
      Loop
  End Sub
Thanks.

Rob.
 

Excel Facts

Create a Pivot Table on a Map
If your data has zip codes, postal codes, or city names, select the data and use Insert, 3D Map. (Found to right of chart icons).
Hello, I cannot say this works but I am thinking setting the time to stop, then checking if now equals that time:

<font face=Courier New><SPAN style="color:#00007F">Public</SPAN> <SPAN style="color:#00007F">Const</SPAN> cRunForTime = Now + "00:01:00"<br>  <br><br><SPAN style="color:#00007F">Sub</SPAN> Phase1()<br>     Sheets("Data Collection and Compilation").Select<br>      <SPAN style="color:#00007F">Do</SPAN> <SPAN style="color:#00007F">Until</SPAN> TimeValue(cRunForTime) = Now<br>      Selection.Offset(-1, 0).Value = Now<br>      Selection.NumberFormat = "0.00%"<br>      Range("h2:h100").Copy<br>      Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _<br>          :=False, Transpose:=False<br>      Selection.Offset(0, 1).Select<br>      <SPAN style="color:#00007F">Loop</SPAN><br>  <SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">Sub</SPAN><br></FONT>
 
Upvote 0

Forum statistics

Threads
1,224,518
Messages
6,179,253
Members
452,900
Latest member
LisaGo

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