Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Optional Arguements for Functions

I want to build a function which takes two optional arguements. If Y
and Z are note provided, I would like to make them equal to 1. How do
I state this within the function? They way I have it below will force
them to 1 regardless.

Private Function New(X As Double, Option Y As Double, Optional Z As
Double)

'if Y and Z are not provided then force them to value of 1
Y = 1.0
Z = 1.0

New = X*Y*Z


---
Message posted from http://www.ExcelForum.com/

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Optional Arguements for Functions

Private Function New(X As Double, Option Y As Double = 1, _
Optional Z As Double = 1)

New = X*Y*Z

End Function

--
Regards,
Tom Ogilvy



ExcelMonkey wrote in message
...
I want to build a function which takes two optional arguements. If Y
and Z are note provided, I would like to make them equal to 1. How do
I state this within the function? They way I have it below will force
them to 1 regardless.

Private Function New(X As Double, Option Y As Double, Optional Z As
Double)

'if Y and Z are not provided then force them to value of 1
Y = 1.0
Z = 1.0

New = X*Y*Z


---
Message posted from http://www.ExcelForum.com/



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,651
Default Optional Arguements for Functions

On Tue, 3 Feb 2004 21:17:19 -0600, ExcelMonkey
wrote:

I want to build a function which takes two optional arguements. If Y
and Z are note provided, I would like to make them equal to 1. How do
I state this within the function? They way I have it below will force
them to 1 regardless.

Private Function New(X As Double, Option Y As Double, Optional Z As
Double)

'if Y and Z are not provided then force them to value of 1
Y = 1.0
Z = 1.0

New = X*Y*Z



Try:

Function Nw(X As Double, Optional Y As Double = 1, Optional Z As Double = 1)

Nw = X * Y * Z

End Function

--ron
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,236
Default Optional Arguements for Functions

Just to add.
Optional arguments are only valid at the end. In other words, you can't have
mandatory arguments following optional ones.


--
Rob van Gelder - http://www.vangelder.co.nz/excel


"Tom Ogilvy" wrote in message
...
Private Function New(X As Double, Option Y As Double = 1, _
Optional Z As Double = 1)

New = X*Y*Z

End Function

--
Regards,
Tom Ogilvy



ExcelMonkey wrote in message
...
I want to build a function which takes two optional arguements. If Y
and Z are note provided, I would like to make them equal to 1. How do
I state this within the function? They way I have it below will force
them to 1 regardless.

Private Function New(X As Double, Option Y As Double, Optional Z As
Double)

'if Y and Z are not provided then force them to value of 1
Y = 1.0
Z = 1.0

New = X*Y*Z


---
Message posted from http://www.ExcelForum.com/





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
Too many arguements? GHall Excel Worksheet Functions 6 December 6th 08 08:58 PM
how can i have more than 30 arguements in a SUM RobG2007 Excel Discussion (Misc queries) 6 July 25th 07 08:28 PM
Nesting Functions with more than 7 arguements tammyj Excel Worksheet Functions 1 September 13th 06 06:39 PM
OR Function with more than 30 arguements James T Excel Discussion (Misc queries) 4 May 12th 06 01:36 AM
Too many arguements pj Excel Discussion (Misc queries) 3 December 6th 05 02:13 PM


All times are GMT +1. The time now is 12:13 AM.

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"