View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
OssieMac OssieMac is offline
external usenet poster
 
Posts: 2,510
Default Repeat a marco with number of times or loop until End

Hi Elton,

The following will perform the loop.

Sub RunInLoop()
Dim i As Long
For i = 1 To 100
Application.Run "SkyDaysHour_X31_H2_Hour"
Next i
End Sub


I am not sure what you are attempting to achieve with the On Error. I
shouldn't think that you will get an error in the loop code as above. Perhaps
you mean in the sub that is being called so it would be as follows. Note the
comments. The On Error needs to be in the sub where the error is likely to be
produced.


Sub SkyDaysHour_X31_H2_Hour()

'The following line goes immediately prior
'to the line that is likely to produce error
On Error Resume Next

'The code likely to produce error here

'The following immediately after the
'line likely to produce error
On Error GoTo 0 'Resumes errror trapping

End Sub

--
Regards,

OssieMac


"Elton Law" wrote:

Dear Expert,
I know this may be easy for some of the experts, but I still how you can
help ...


Say following scripts ...
I would like to run this scripts for 100 times ...
Can you advise how to write?

Application.Run "SkyDaysHour_X31_H2_Hour"


Can you also tell how to write loop until it reach error and jump to next
step ..?

Thanks