Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming,microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 14
Default UDF Raising an error

Hi

How can i get a user defined function to return an error code like #n/a.

many thank

d


  #2   Report Post  
Posted to microsoft.public.excel.programming,microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 35,218
Default UDF Raising an error

Option Explicit
Function myFunc(myVal As Variant) As Variant

If IsNumeric(myVal) Then
myFunc = myVal * 2
Else
myFunc = CVErr(xlErrNA)
End If

End Function



DMc2005 wrote:

Hi

How can i get a user defined function to return an error code like #n/a.

many thank

d


--

Dave Peterson
  #3   Report Post  
Posted to microsoft.public.excel.programming,microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 11,272
Default UDF Raising an error

Just a thought. Using an error like #N/A is not good user interfacing IMO.
Far better to give a meanigful message (yeah, I know Excel does, but that is
a throwback from years ago).

Using Dave's UDF as an example

Option Explicit

Function myFunc(myVal As Variant) As Variant

If IsNumeric(myVal) Then
myFunc = myVal * 2
Else
myFunc = "#Value must be numeric"
End If

End Function


--
HTH

Bob Phillips

(remove nothere from email address if mailing direct)

"DMc2005" wrote in message
...
Hi

How can i get a user defined function to return an error code like #n/a.

many thank

d




  #4   Report Post  
Posted to microsoft.public.excel.programming,microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 733
Default UDF Raising an error

Bob Phillips wrote...
Just a thought. Using an error like #N/A is not good user interfacing IMO.
Far better to give a meanigful message (yeah, I know Excel does, but that is
a throwback from years ago).

Using Dave's UDF as an example

Option Explicit

Function myFunc(myVal As Variant) As Variant

If IsNumeric(myVal) Then
myFunc = myVal * 2
Else
myFunc = "#Value must be numeric"
End If

End Function

....

This philosophical point begs for discussion. The advantage of
returning a true error value is that there are functions available to
trap error values. In this case, the expected result is numeric, so
returning text would signal an error. However, in general udfs could
return text, and in those cases returning textual error messages could
make subsequent processing more complex. Also, it's generally good to
stick with a single, consistent error and exception handling approach,
and that's means conforming to how Excel's built-in functions work even
if you don't like how they work.

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
Fund Raising Chart samiauthor Charts and Charting in Excel 1 December 28th 09 09:39 PM
raising multiple cells containing numbers by a percentage Tammy Dean[_2_] Excel Discussion (Misc queries) 3 July 11th 08 02:48 PM
UDF Raising an error DMc2005 Excel Worksheet Functions 3 October 13th 05 11:46 PM
run-time error '1004': Application-defined or object-deifined error [email protected] Excel Programming 5 August 10th 05 09:39 PM
Automation Error, Unknown Error. Error value - 440 Neo[_2_] Excel Programming 0 May 29th 04 05:26 AM


All times are GMT +1. The time now is 11:19 PM.

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

About Us

"It's about Microsoft Excel"