Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,651
Default UDF Returning an Error Value: How to?

Is there a method of having a UDF return a "real" Excel error value such as
#NUM! ? In other words, the value returned should give a TRUE result from the
ISERR and/or ISERROR and/or ISNA worksheet functions (depending on the error)
and also give the correct response to the ERROR.TYPE worksheet function?

Thanks.


--ron
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,302
Default UDF Returning an Error Value: How to?

Hi Ron,

By way of example:

'=========================
Function TotalCost(price As Range, Quantity As Range)
Dim N As Integer
Dim total As Double
If price.Count < Quantity.Count Then
TotalCost = CVErr(xlErrValue)
Else
total = 0
For N = 1 To UBound(price())
If Not IsNumeric(price(N)) _
Or Not IsNumeric(Quantity(N)) Then
TotalCost = CVErr(xlErrNum)
Exit Function
End If
total = total + price(N) * Quantity(N)
Next N
TotalCost = total
End If
End Function
'<<=========================

---
Regards,
Norman



"Ron Rosenfeld" wrote in message
...
Is there a method of having a UDF return a "real" Excel error value such
as
#NUM! ? In other words, the value returned should give a TRUE result from
the
ISERR and/or ISERROR and/or ISNA worksheet functions (depending on the
error)
and also give the correct response to the ERROR.TYPE worksheet function?

Thanks.


--ron



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,651
Default UDF Returning an Error Value: How to?

Thank you Norman,

Had it not been for you, I would not have been able to find that list of
constants. It's not always easy for me to search through HELP for this sort of
information. But I found them using the Object Browser. I never would have
tumbled to it myself.

Thanks.

--Ron

On Sat, 17 Sep 2005 12:42:59 +0100, "Norman Jones"
wrote:

Hi Ron,

By way of example:

'=========================
Function TotalCost(price As Range, Quantity As Range)
Dim N As Integer
Dim total As Double
If price.Count < Quantity.Count Then
TotalCost = CVErr(xlErrValue)
Else
total = 0
For N = 1 To UBound(price())
If Not IsNumeric(price(N)) _
Or Not IsNumeric(Quantity(N)) Then
TotalCost = CVErr(xlErrNum)
Exit Function
End If
total = total + price(N) * Quantity(N)
Next N
TotalCost = total
End If
End Function
'<<=========================

---
Regards,
Norman



"Ron Rosenfeld" wrote in message
.. .
Is there a method of having a UDF return a "real" Excel error value such
as
#NUM! ? In other words, the value returned should give a TRUE result from
the
ISERR and/or ISERROR and/or ISNA worksheet functions (depending on the
error)
and also give the correct response to the ERROR.TYPE worksheet function?

Thanks.


--ron



--ron
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
Formula returning an error gotroots Excel Worksheet Functions 2 January 4th 10 04:53 PM
SEARCH function returning #VALUE! error jhchan Excel Discussion (Misc queries) 1 May 25th 09 04:36 PM
Formula returning #N/A Error---why??? Excel User Excel Worksheet Functions 4 September 26th 05 02:25 PM
Vlookup in VB not returning anything error Grant Excel Programming 5 August 31st 04 03:29 AM
Returning Error from Functions LeninVMS[_4_] Excel Programming 3 April 9th 04 06:27 PM


All times are GMT +1. The time now is 12:04 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"