Thread
:
UDF/VBA Function, trap error, avoid #VALUE!
View Single Post
#
5
Posted to microsoft.public.excel.programming
JE McGimpsey
external usenet poster
Posts: 4,624
UDF/VBA Function, trap error, avoid #VALUE!
Hmm... I get
=HelloWorld(FALSE) returns "Hello World"
=HelloWorld(TRUE) returns "ERROR HAPPENED"
I can cause an error if I use an argument that can't be coerced to a
Boolean:
=HelloWorld("TRUE ") returns #VALUE!
In article .com,
wrote:
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!
Reply With Quote
JE McGimpsey
View Public Profile
Find all posts by JE McGimpsey