Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
hi,
can anyone advise as to how do i use an optional argument in a function? thanks in advance |
#2
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Interpreting "comma" where an optional argument is | Excel Worksheet Functions | |||
Compile Error Argument Not optional | Excel Discussion (Misc queries) | |||
Function (array argument, range argument, string argument) vba | Excel Programming | |||
Complie Error- Argument not optional | Excel Programming | |||
Problem with optional parameters in Excel Automation Add-in worksheet function | Excel Programming |