ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Skip Errors (https://www.excelbanter.com/excel-programming/428871-skip-errors.html)

Elton Law[_2_]

Skip Errors
 
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



royUK[_122_]

Skip Errors
 

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
--------------------


--
royUK

Hope that helps, RoyUK
For tips & examples visit my 'web site' (http://www.excel-it.com/)
------------------------------------------------------------------------
royUK's Profile: http://www.thecodecage.com/forumz/member.php?userid=15
View this thread: http://www.thecodecage.com/forumz/sh...ad.php?t=99814



All times are GMT +1. The time now is 12:42 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com