hi,
can anyone advise as to how do i use an optional argument in a function?
thanks in advance
hi,
can anyone advise as to how do i use an optional argument in a function?
thanks in advance
What do you want to do? And what are you uncertain about?
--
Kind Regards,
Niek Otten
Microsoft MVP - Excel
"visitor" <[email protected]> wrote in message
news:[email protected]...
> hi,
>
> can anyone advise as to how do i use an optional argument in a function?
>
> thanks in advance
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" <[email protected]> wrote in message
news:[email protected]...
> hi,
>
> can anyone advise as to how do i use an optional argument in a
> function?
>
> thanks in advance
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" <[email protected]> wrote in message
news:[email protected]...
> 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" <[email protected]> wrote in message
> news:[email protected]...
>> hi,
>>
>> can anyone advise as to how do i use an optional argument in a function?
>>
>> thanks in advance
>
>
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" <[email protected]> wrote in message
news:%23oQk9N%[email protected]...
> 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" <[email protected]> wrote in message
> news:[email protected]...
>> 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" <[email protected]> wrote in message
>> news:[email protected]...
>>> hi,
>>>
>>> can anyone advise as to how do i use an optional argument in
>>> a function?
>>>
>>> thanks in advance
>>
>>
>
>
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks