I have a for next loop....
I need to re loop The for next at every 5 minutes... how to ? But
only when the for next is finished.
Example:
For i = 0 to 10
Next i
Here stop for 5 minutes
Re loop the for next
Ecc....
re loop for next
-
- Administrator
- Posts: 78524
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: re loop for next
If it's in Excel:
Run StartLooping when you want to start, and run StopLooping when you want to stop.
Code: Select all
Dim dtmSchedule as Date
Sub StartLooping()
Dim i As Long
For i = 0 To 10
...
Next i
dtmSchedule = Now + TimeSerial(0, 5, 0)
Application.OnTime dtmSchedule, "StartLooping"
End Sub
Sub StopLooping()
Application.OnTime dtmSchedule, "StartLooping", , False
End Sub
Best wishes,
Hans
Hans
-
- PlatinumLounger
- Posts: 4362
- Joined: 26 Apr 2010, 17:36
Re: re loop for next
ops...HansV wrote:If it's in Excel:
Run StartLooping when you want to start, and run StopLooping when you want to stop.Code: Select all
Dim dtmSchedule as Date Sub StartLooping() Dim i As Long For i = 0 To 10 ... Next i dtmSchedule = Now + TimeSerial(0, 5, 0) Application.OnTime dtmSchedule, "StartLooping" End Sub Sub StopLooping() Application.OnTime dtmSchedule, "StartLooping", , False End Sub
but really i need in vba for Excel.
sorry me
errror in:
Application.OnTime dtmSchedule, "StartLooping", , False
You do not have the required permissions to view the files attached to this post.
-
- Administrator
- Posts: 78524
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
-
- gamma jay
- Posts: 25455
- Joined: 17 Mar 2010, 17:33
- Location: Cape Town
Re: re loop for next
You can only run StopLooping while StartLooping is running.
If you run StopLooping on its own it will debug as there is nothing to stop.
If you run StopLooping on its own it will debug as there is nothing to stop.
Regards,
Rudi
If your absence does not affect them, your presence didn't matter.
Rudi
If your absence does not affect them, your presence didn't matter.
-
- PlatinumLounger
- Posts: 4362
- Joined: 26 Apr 2010, 17:36
Re: re loop for next
HansV wrote:The code runs in Excel, I tested it.
Resolved....
but how to stop the timer routine and exit sub if the cirrent tme is => 16:30?
-
- gamma jay
- Posts: 25455
- Joined: 17 Mar 2010, 17:33
- Location: Cape Town
Re: re loop for next
Try this...
Note: Its air code...untested!
Note: Its air code...untested!
Code: Select all
Option Explicit
Dim dtmSchedule As Date
Sub StartLooping()
Dim i As Long
For i = 0 To 10
'...
Next i
If Now >= TimeValue("16:30:00 PM") Then
StopLooping
Else
dtmSchedule = Now + TimeSerial(0, 5, 0)
Application.OnTime dtmSchedule, "StartLooping"
End If
End Sub
Sub StopLooping()
On Error Resume Next
Application.OnTime dtmSchedule, "StartLooping", , False
End Sub
Regards,
Rudi
If your absence does not affect them, your presence didn't matter.
Rudi
If your absence does not affect them, your presence didn't matter.