LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default Generating Error for UDF

Hi
This is something that has intrigued me for some time but I've never really
faced up to it!

When creating a user defined worksheet function how do I generate an error?

For example the following gives me a #VALUE! error where I want one (FTE
must be between 0 & 1 inclusive) but I'm not sure I've used a valid method.

Using this function in cell A1, =SalCost06(A2,A3) with a salary of 20000 in
A2 and FTE = 0.5 in A3 I get the expected result (12500). Change A3 to 5
and I get #VALUE!.

Function SalCost06(Salary As Double, Optional FTE As Single = 1) As Double
Application.Volatile
If FTE < 0 Or FTE 1 Then
SalCost06 = Error 'this does the job but I don't understand!!
Exit Function
End If
SalCost06 = (Salary * FTE) + (Salary * 0.25 * FTE)
End Function

To expand this, if I needed to divide something by the FTE and FTE = 0 I
would want a #DIV/0! error but I can't get it - or rather I don't how to (or
if I can) get it.

BTW there is much more scope for error in this function as the calculation
is considerably more involved than I've shown in the example, but that's for
me to handle within the function!! This is just about reporting an error in
the worksheet!

TIA & Happy Friday
--
Rgds, Loomah


 
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
Excel 2007 Solver Internal Error When Generating Answer Report Don S. Excel Discussion (Misc queries) 18 November 7th 12 07:33 PM
Generating a list Dave[_3_] Excel Worksheet Functions 1 April 4th 07 12:35 AM
Generating 1004 error messages while running a marco niceman Excel Programming 2 May 25th 06 01:15 PM
Help generating combinations JamRock Excel Programming 3 March 2nd 06 07:38 PM
Generating Ranges in VBA cmk18[_4_] Excel Programming 0 June 16th 05 08:12 PM


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