LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,045
Default UDF function with Optional Paramters Problem

On Thu, 12 Aug 2010 15:33:15 +0200, "Charlotte E"
wrote:

As an aside, it is a bit shorter (eliminates the IF statement) to
write your UDF this way:

=====================
Function FTE(Hours, Optional Periods = 26.1)
Application.Volatile
FTE = Hours / (Periods * 70)
End Function
=====================


Problem with that solution is that the function is not as 'robust' - the
user can force an error by entering af negative number of periods!

I think you should use this instead, which will trap such errors:

Function FTE(FTE_Hours, Optional FTE_Periods As Double = -1)
Application.Volatile
If FTE_Periods <= 0 Then FTE_Periods = 26.1
FTE = FTE_Hours / (FTE_Periods * 70)
End Function


CE


Of course, the user did not specify that he wanted to exclude a
negative number for the Periods variable.

However, if you feel data entry requires validation, why limit the
validation to just the Periods value, and why limit that to only
positive values?
 
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
Paramters or Arugment Auto-Label for User-Defined Function [email protected] Excel Worksheet Functions 5 April 22nd 08 06:21 PM
Problem auto generating e-mail to several recipients - argument not optional error message [email protected] Excel Programming 8 June 8th 07 03:21 PM
Representation of optional parameters in Function arguments window compound[_5_] Excel Programming 0 January 17th 06 11:32 PM
optional argument in a function visitor Excel Programming 4 May 13th 05 07:41 PM
Problem with optional parameters in Excel Automation Add-in worksheet function Mike Gilkeson Excel Programming 0 February 18th 04 02:13 PM


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