Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
Ayo Ayo is offline
external usenet poster
 
Posts: 489
Default Function Declarations !!!!!!!!!!!!!!!!!!!!!!

How do you declare a variable as OPTIONAL in a UDF. I have a function that I
use in one of my macros but I would like to declare at least one of the
variables as an optional variable. I am not sure how to do that.
Any ideas?

Thanks
Ayo
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 83
Default Function Declarations !!!!!!!!!!!!!!!!!!!!!!

On Wed, 14 Apr 2010 12:02:01 -0700, Ayo
wrote:

How do you declare a variable as OPTIONAL in a UDF. I have a function that I
use in one of my macros but I would like to declare at least one of the
variables as an optional variable. I am not sure how to do that.
Any ideas?

Thanks
Ayo


Have a look under "Using a Variable Number Of Parameters" he

http://www.cpearson.com/excel/writin...ionsinvba.aspx

Hope this helps / Lars-Åke
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,651
Default Function Declarations !!!!!!!!!!!!!!!!!!!!!!

On Wed, 14 Apr 2010 12:02:01 -0700, Ayo wrote:

How do you declare a variable as OPTIONAL in a UDF. I have a function that I
use in one of my macros but I would like to declare at least one of the
variables as an optional variable. I am not sure how to do that.
Any ideas?

Thanks
Ayo


Look at VBA Help for the Optional keyword. Here's an example, but there are
restrictions on its use you should be familiar with.

Function foo(s As String, n As Long, Optional o As Variant, _
Optional m As String = "bar") As String
....
....
End Function
--ron
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 395
Default Function Declarations !!!!!!!!!!!!!!!!!!!!!!

The key thing to remember is that every variable you declare after the first
optional parameter will also be optional (you cannot have required, then
optional, then required)

Here is a real one from one of my workbooks:
Function PullAllRawData(SourceSheet As Worksheet, _
DestSheet As Worksheet, _
Optional PathOnly As String, _
Optional MyFullFilePath As String, _
Optional TitleString As String)

In this case, it isn't a UDF, but I'd expect it should work the same way.

HTH,
Keith

"Ayo" wrote:

How do you declare a variable as OPTIONAL in a UDF. I have a function that I
use in one of my macros but I would like to declare at least one of the
variables as an optional variable. I am not sure how to do that.
Any ideas?

Thanks
Ayo

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
declarations jimbo_jones[_10_] Excel Programming 2 September 23rd 05 06:50 PM
Declarations Procedure and Duplicate Declarations Neal Zimm Excel Programming 3 May 31st 05 01:01 AM
Understanding declarations Greg[_16_] Excel Programming 1 January 26th 05 09:35 PM
Help with Array Declarations Mark \(InWales\)[_19_] Excel Programming 4 December 20th 04 06:39 AM
Capitalization in Declarations Phil Hageman[_3_] Excel Programming 16 December 24th 03 11:01 PM


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