View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.programming
[email protected] StevensSpam@cfl.rr.com is offline
external usenet poster
 
Posts: 9
Default UDF/VBA Function, trap error, avoid #VALUE!

I have created a new function to try to recreate an example function
that mimics my intent:

Public Function HelloWorld(causeError As Boolean) As String

On Error GoTo ErrorHandler
If (causeError) Then
Err.Raise 1234
Else
HelloWorld = "Hello World"
End If

FunctionExit:
Exit Function

ErrorHandler:
Err.Clear
HelloWorld = "ERROR HAPPENED"
Resume FunctionExit

End Function

=HelloWorld(FALSE) returns "Hello World"
=HelloWorld(TRUE) returns #VALUE!