ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Error handling (https://www.excelbanter.com/excel-programming/416870-error-handling.html)

GPO

Error handling
 
(excel 2000, 2003, 2007)

Hello All

I have a function where I want the error handling for the most part to be
On Error GoTo HandleError

but for certain blocks I want it to be
On Error Resume Next

How do I do this?

Regards

GPO



joel

Error handling
 
Just switch between the two errors mode as required

On Error GoTo HandleError
'section 1 code
On Error Resume Next
'section 2 code
On Error GoTo HandleError
'section 3 code


"GPO" wrote:

(excel 2000, 2003, 2007)

Hello All

I have a function where I want the error handling for the most part to be
On Error GoTo HandleError

but for certain blocks I want it to be
On Error Resume Next

How do I do this?

Regards

GPO



Bob Phillips[_3_]

Error handling
 
I tend to handle that by placing the Resume Next code into a separate
procedure, as the error handler is reset on exit.

Sub TestError()

On Error GoTo HandleError

'do stuff

Call CalledProc

Debug.Print 1 / 0

Exit Sub

HandleError:
MsgBox Err.Number & " : " & Err.Description
End Sub

Function CalledProc()

On Error Resume Next
Debug.Print 1 / 0
End Function

It may seem unnecessary, but I find it keeps the code more structured, and
gives m e all the control that I need

--
__________________________________
HTH

Bob

"GPO" wrote in message
...
(excel 2000, 2003, 2007)

Hello All

I have a function where I want the error handling for the most part to be
On Error GoTo HandleError

but for certain blocks I want it to be
On Error Resume Next

How do I do this?

Regards

GPO






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

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