Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default Returning custom errors from UDFs

I'm trying to return a custom error to Excel from my UDF. The calling
cell always displays #Value! when an error occurs. The Error.Type is 3,
corresponding to #Value!. Why don't I get my custom error number back?

Dave



Public Function Foo(intTest as Integer) As Variant

Dim lngFuncReturn As Long

On Error GoTo Foo_Error

'...Get the description
lngFuncReturn = MyFoo(intTest)
If (lngFuncReturn < STATUS_SUCCESS) Then

'...Return a custom error number
Foo = CVErr(lngFuncReturn)

Else

'...Make the function value the returned value:
Foo = lngFuncReturn

End If

Foo_Resume:
Exit Function

Foo_Error:

Foo = CVErr(xlErrNA)
Resume Foo_Resume

End Function

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,080
Default Returning custom errors from UDFs

Try:

Foo = CInt(CVErr(lngFuncReturn))

--

Vasant


"Dave" wrote in message
oups.com...
I'm trying to return a custom error to Excel from my UDF. The calling
cell always displays #Value! when an error occurs. The Error.Type is 3,
corresponding to #Value!. Why don't I get my custom error number back?

Dave



Public Function Foo(intTest as Integer) As Variant

Dim lngFuncReturn As Long

On Error GoTo Foo_Error

'...Get the description
lngFuncReturn = MyFoo(intTest)
If (lngFuncReturn < STATUS_SUCCESS) Then

'...Return a custom error number
Foo = CVErr(lngFuncReturn)

Else

'...Make the function value the returned value:
Foo = lngFuncReturn

End If

Foo_Resume:
Exit Function

Foo_Error:

Foo = CVErr(xlErrNA)
Resume Foo_Resume

End Function



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default Returning custom errors from UDFs

That just returns the integer value, which I can't distiguish from the
normal return values.

Dave

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,080
Default Returning custom errors from UDFs

Sorry; I thought you wanted the error number back. What would you like to
see in the cell?

--

Vasant


"Dave" wrote in message
oups.com...
That just returns the integer value, which I can't distiguish from the
normal return values.

Dave



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Returning custom errors from UDFs

hard to tell from what you show, but Excel will show #Value for any error
returned except the defined errors. There is no provision for custom
errors.

--
Regards,
Tom Ogilvy

"Dave" wrote in message
oups.com...
I'm trying to return a custom error to Excel from my UDF. The calling
cell always displays #Value! when an error occurs. The Error.Type is 3,
corresponding to #Value!. Why don't I get my custom error number back?

Dave



Public Function Foo(intTest as Integer) As Variant

Dim lngFuncReturn As Long

On Error GoTo Foo_Error

'...Get the description
lngFuncReturn = MyFoo(intTest)
If (lngFuncReturn < STATUS_SUCCESS) Then

'...Return a custom error number
Foo = CVErr(lngFuncReturn)

Else

'...Make the function value the returned value:
Foo = lngFuncReturn

End If

Foo_Resume:
Exit Function

Foo_Error:

Foo = CVErr(xlErrNA)
Resume Foo_Resume

End Function





  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default Returning custom errors from UDFs

I'm stuck with #Value!... That's useless.

  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,758
Default Returning custom errors from UDFs

Return your own string:

#Thisismyownerror!

You won't be able to use =iserror(), but maybe that's not necessary.

Dave wrote:

I'm stuck with #Value!... That's useless.


--

Dave Peterson
  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default Returning custom errors from UDFs

I think I'll use Dave's suggestion of #Thisismyownerror! I did have all
the error code worked out and a translation macro written. Now I'll
just retrun the translated message surrounded by #...! I thought I
could return the error code number, test it with IsError and then allow
the user to translate it with my other macro.

Thanks for everyone's suggestions & help.

Dave

  #9   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default Returning custom errors from UDFs

You can't have custom error values in functions. You are limited
to the values in XLCVError.


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com


"Dave" wrote in message
oups.com...
I'm trying to return a custom error to Excel from my UDF. The
calling
cell always displays #Value! when an error occurs. The
Error.Type is 3,
corresponding to #Value!. Why don't I get my custom error
number back?

Dave



Public Function Foo(intTest as Integer) As Variant

Dim lngFuncReturn As Long

On Error GoTo Foo_Error

'...Get the description
lngFuncReturn = MyFoo(intTest)
If (lngFuncReturn < STATUS_SUCCESS) Then

'...Return a custom error number
Foo = CVErr(lngFuncReturn)

Else

'...Make the function value the returned value:
Foo = lngFuncReturn

End If

Foo_Resume:
Exit Function

Foo_Error:

Foo = CVErr(xlErrNA)
Resume Foo_Resume

End Function



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
vlookup returning Errors (ISNA formula) Nora[_2_] Excel Worksheet Functions 3 January 3rd 08 04:29 PM
Help on sumproduct returning errors Pierre Excel Worksheet Functions 2 November 16th 06 04:00 PM
VLOOKUP returning errors Dave F Excel Worksheet Functions 4 September 6th 06 06:35 PM
xlodbc returning no rows & no errors Boultonsj Excel Programming 3 October 7th 04 10:57 AM
Formulas returning errors when reference columns are deleted Ian M[_2_] Excel Programming 1 May 3rd 04 07:51 AM


All times are GMT +1. The time now is 01:17 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"