+ Reply to Thread
Results 1 to 6 of 6

Passing date as optional parameter to function

  1. #1
    Forum Contributor
    Join Date
    12-06-2012
    Location
    South Africa
    MS-Off Ver
    Excel 2010
    Posts
    204

    Passing date as optional parameter to function

    I want to create a function to return a value from a sheet. The first parameter is a account number that must be passed. The second parameter is a date but that I want as an optional parameter. So if a date is entered use that date otherwise use today date as parameter.
    Please Login or Register  to view this content.
    What do I enter for = !!!?

    Or do I have to leave out the = !!! part and set it inside the function?

    How do I check inside the function if the date was passed or not?

    Dates in VB/VBA is a pain for me

  2. #2
    Forum Expert Debraj Roy's Avatar
    Join Date
    09-27-2012
    Location
    New Delhi,India
    MS-Off Ver
    Excel 2013
    Posts
    1,469

    Re: Passing date as optional parameter to function

    Try something like below..

    Please Login or Register  to view this content.
    Regards!
    =DEC2HEX(3563)

    If you like someone's answer, click the star to give them a reputation point for that answer...

  3. #3
    Forum Guru :) Sixthsense :)'s Avatar
    Join Date
    01-01-2012
    Location
    India>Tamilnadu>Chennai
    MS-Off Ver
    2003 To 2010
    Posts
    12,788

    Re: Passing date as optional parameter to function

    Please Login or Register  to view this content.


    If your problem is solved, then please mark the thread as SOLVED>>Above your first post>>Thread Tools>>
    Mark your thread as Solved


    If the suggestion helps you, then Click *below to Add Reputation

  4. #4
    Forum Expert Debraj Roy's Avatar
    Join Date
    09-27-2012
    Location
    New Delhi,India
    MS-Off Ver
    Excel 2013
    Posts
    1,469

    Re: Passing date as optional parameter to function

    Quote Originally Posted by Debraj Roy View Post
    Try something like below..

    Please Login or Register  to view this content.
    OOPS.. My fault, IsMissing can only works with variant data-type..

    You may have to change the datatype for the Optional part / return data-type..
    try something like this..

    Please Login or Register  to view this content.

  5. #5
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    22,015

    Re: Passing date as optional parameter to function

    You can just compare it to 0:
    Please Login or Register  to view this content.
    Everyone who confuses correlation and causation ends up dead.

  6. #6
    Forum Contributor
    Join Date
    12-06-2012
    Location
    South Africa
    MS-Off Ver
    Excel 2010
    Posts
    204

    Re: Passing date as optional parameter to function

    romperstomper. Comparing it to 0 does the job.

    Sixthsence: If I display the variable without assigning a date to it it only displays 12:00:00 AM. It doesn't display a date.

    Debraj Roy: I prefer not to use variants if at all possible. My var is declared as a date.

    Thanks people.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Code for passing a date as a parameter when pulling data
    By jaimealvarez in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 04-25-2012, 11:52 AM
  2. Passing date parameter in sql query
    By farrukh in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 11-09-2011, 03:47 AM
  3. optional parameter
    By Ben in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 04-21-2006, 02:15 PM
  4. [SOLVED] format optional parameter
    By compound in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 09-26-2005, 06:05 PM
  5. format optional parameter
    By compound in forum Excel General
    Replies: 0
    Last Post: 09-16-2005, 01:20 PM

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