+ Reply to Thread
Results 1 to 4 of 4

date returning time in vba intermediate window

Hybrid View

Guest date returning time in vba... 12-21-2005, 04:35 PM
Guest Re: date returning time in... 12-21-2005, 09:10 PM
Guest Re: date returning time in... 12-23-2005, 10:40 AM
Guest Re: date returning time in... 12-24-2005, 10:35 PM
  1. #1
    papa jonah
    Guest

    date returning time in vba intermediate window

    The following is an example of some code that I am using in a process
    to make charts. While troubleshooting a date calculation error, I
    found out that "lastdate" returns a value of 12:00:00 AM in the
    intermediate window.
    Lastdate is dim'd as public lastdate as date.

    ans = MsgBox("Do you want to lock in a review period end date?",
    vbYesNo)
    If ans = vbYes Then 'lock in a date for the end of review period for
    subsequent runs
    LastDate = InputBox("What date (MM/DD/YYYY) will mark the end of
    the review periods?", , "10/1/2006")
    Else: LastDate = CDate(Now()) 'not sure what CDATE does
    End If

    What am I doing wrong that would cause this to indicate a time instead
    of a date as I entered?

    TIA


  2. #2
    Dick Kusleika
    Guest

    Re: date returning time in vba intermediate window

    papa jonah wrote:
    > The following is an example of some code that I am using in a process
    > to make charts. While troubleshooting a date calculation error, I
    > found out that "lastdate" returns a value of 12:00:00 AM in the
    > intermediate window.
    > Lastdate is dim'd as public lastdate as date.
    >
    > ans = MsgBox("Do you want to lock in a review period end date?",
    > vbYesNo)
    > If ans = vbYes Then 'lock in a date for the end of review period for
    > subsequent runs
    > LastDate = InputBox("What date (MM/DD/YYYY) will mark the end of
    > the review periods?", , "10/1/2006")
    > Else: LastDate = CDate(Now()) 'not sure what CDATE does
    > End If
    >
    > What am I doing wrong that would cause this to indicate a time instead
    > of a date as I entered?
    >

    PJ

    If the "date" entered is zero (presumably from cancelling the input box),
    then the variable will show the time. Put this in the immediate window:

    ?clng(lastdate)
    0
    ?format(lastdate,"mm/dd/yyyy")
    12/30/1899

    Why a date variable would show 12:00 AM instead of 12/30/1899 is a mystery
    to me. You probably need to add some code that makes sure the user doesn't
    cancel the input box.

    --
    **** Kusleika
    MVP-Excel
    www.dailydoseofexcel.com



  3. #3
    papa jonah
    Guest

    Re: date returning time in vba intermediate window

    I haven't tried your troubleshooting yet, but this occurs without
    cancelling the input box.


  4. #4
    Dick Kusleika
    Guest

    Re: date returning time in vba intermediate window

    papa jonah wrote:
    > I haven't tried your troubleshooting yet, but this occurs without
    > cancelling the input box.


    I pasted your code into a module and ran it, like this

    Sub test()

    Dim ans As Long
    Dim LastDate As Date

    ans = MsgBox("Do you want to lock in a review period end date?", vbYesNo)
    If ans = vbYes Then 'lock in a date for the end of review period for
    subsequent runs
    LastDate = InputBox("What date (MM/DD/YYYY) will mark the end of the
    review periods?", , "10/1/2006")
    Else
    LastDate = CDate(Now()) 'not sure what CDATE does
    End If
    Stop

    End Sub

    At "Stop", I went to the Immediate Window and typed ?lastdate. The only way
    I could get it to return 12:00 AM was to enter zero in the input box. If I
    put anything resembling a date, or any other integer, the immediate window
    returned a date. If I put in text, I got a type mismatch. Somehow, you're
    getting a zero for LastDate and it has to be related to what you're entering
    in the input box. What have you entered that gives you that result?
    Everything? What version of Excel are you using?


    --
    **** Kusleika
    MVP-Excel
    www.dailydoseofexcel.com



+ 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