Skip Errors

E

Elton Law

Dear Expert,

Can I set a script at the very beginning of the macro to overrule all errors
it encounter ?

That is ... it would not halt / stop ....
Even face errors ... immediately goto next line ....

A script at the beginning to rule this ....
Just go ahead and skip the error lines and keep on running with next line.

Thanks
 
R

royUK

You can do that like this

Code:
--------------------

Option Explicit

Sub x()
On Error Resume Next
'code
On Error GoTo 0
End Sub

--------------------


However just instructing Excel to ignore errors is a bad idea, you
should fix the errors in your code.

Also, remember that if you add an error habdler like this whilst
developing the code then you will not be able to pinpoint any errors in
your code. Error handlers should be added after the code is working
correctly.

You can use this type of error handler to return a messagebox with
details of the error

Code:
--------------------

Option Explicit

Sub testmacro()

On Error GoTo testmacro_Error
'REPLCE WITH your code
Rows(Rows.Count + 1).Select
On Error GoTo 0
Exit Sub

testmacro_Error:
MsgBox "Error " & Err.Number & " (" & Err.Description & _
") in procedure testmacro of Module Module1"
End Sub
 
Top