PDA

View Full Version : How to insert a wait timer in for loop



uaku
08-10-2011, 10:34 AM
Hi,
I have a for loop in Excel VBA,

For Val in Range("A1:A10")
.
.
.
.
' I would like to insert time delay between each execution.
Next Val

How can I achieve this, any help would be greatly appreciated.

Bob Phillips
08-10-2011, 10:47 AM
Public Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)

Sub MyCode()
For Val in Range("A1:A10")

'
'
'
Sleep 1000 * 3 ' 3 seconds
Next Val
End Sub

uaku
08-10-2011, 10:57 AM
hi, I tried this code it work fine for 3 seconds, when I gave 59 seconds it did not execute. It gave me error at the "Sleep ......" line. Does it have to be small wait time? There is a way I can give one or two minute delay?

Thanks

Bob Phillips
08-10-2011, 11:25 AM
If you are happy that it 'freezes', then you could use Wait, look it up in VBA.

Paul_Hossler
08-10-2011, 06:08 PM
It gave me error at the "Sleep ......" line.


What was your line?

Paul

Bob Phillips
08-11-2011, 01:02 AM
That would be an overflow error Paul.