ExcelBanter

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

[email protected]

VBA: Error handling
 
I have created a function that returns a string. When it fails, Excel
reports "#VALUE!". I would like to report my description of the error
instead. I have tried to use error handling, but it seems to be
ignored. In the area in which I "Try to do some useful Stuff", an error
occasionally occurs. The debugger shows that control does not transfer
to my ErrorHandler. Instead, execution ends immediately, and the cell
value is set to "#VALUE!".

Public Function myFunction() As String
On Error GoTo ErrorHandler

' Try to do some useful Stuff

myFunction = "RESULT"

FunctionExit:
Exit Function

ErrorHandler:
Err.Clear
myFunction = "My Error Description"
Resume FunctionExit

End Function

Thanks for your assistance!



All times are GMT +1. The time now is 04:40 AM.

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