+ Reply to Thread
Results 1 to 5 of 5

optional argument in a function

  1. #1
    visitor
    Guest

    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. #2
    Niek Otten
    Guest

    Re: 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" <[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




  3. #3
    Chip Pearson
    Guest

    Re: 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" <[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




  4. #4
    Niek Otten
    Guest

    Re: 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" <[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

    >
    >




  5. #5
    Chip Pearson
    Guest

    Re: 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" <[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

    >>
    >>

    >
    >




+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1