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 argument in a function

hi,

can anyone advise as to how do i use an optional argument in a function?

thanks in advance
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,440
Default optional argument in a function

What do you want to do? And what are you uncertain about?

--

Kind Regards,

Niek Otten

Microsoft MVP - Excel

"visitor" wrote in message
...
hi,

can anyone advise as to how do i use an optional argument in a function?

thanks in advance



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default optional argument in a function

Try something like the following:


Function Test(Optional X As Variant) As Integer
If IsMissing(X) Then
Test = 0
Else
Test = X + 1
End If
End Function

--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com



"visitor" wrote in message
...
hi,

can anyone advise as to how do i use an optional argument in a
function?

thanks in advance



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,440
Default optional argument in a function

Note that this only works correctly if you declare the optional argument as
Variant, or omit any declaration, which results in the argument being
treated as a Variant too.

--

Kind Regards,

Niek Otten

Microsoft MVP - Excel

"Chip Pearson" wrote in message
...
Try something like the following:


Function Test(Optional X As Variant) As Integer
If IsMissing(X) Then
Test = 0
Else
Test = X + 1
End If
End Function

--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com



"visitor" wrote in message
...
hi,

can anyone advise as to how do i use an optional argument in a function?

thanks in advance





  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default optional argument in a function

Just to follow up, the argument must be Variant only if you want
to use IsMissing. Optional arguments themselves may be of any
data type. If an argument is omitted, its default value (0, "",
or Nothing) will be used.

Optional argument must follow required arguments.

--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com


"Niek Otten" wrote in message
...
Note that this only works correctly if you declare the optional
argument as Variant, or omit any declaration, which results in
the argument being treated as a Variant too.

--

Kind Regards,

Niek Otten

Microsoft MVP - Excel

"Chip Pearson" wrote in message
...
Try something like the following:


Function Test(Optional X As Variant) As Integer
If IsMissing(X) Then
Test = 0
Else
Test = X + 1
End If
End Function

--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com



"visitor" wrote in message
...
hi,

can anyone advise as to how do i use an optional argument in
a function?

thanks in advance









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
Interpreting "comma" where an optional argument is Epinn Excel Worksheet Functions 4 January 17th 07 12:04 AM
Compile Error Argument Not optional [email protected] Excel Discussion (Misc queries) 1 August 16th 06 04:58 PM
Function (array argument, range argument, string argument) vba Witek[_2_] Excel Programming 3 April 24th 05 03:12 PM
Complie Error- Argument not optional Roberta Excel Programming 5 April 4th 05 02:31 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:14 AM.

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"