Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 595
Default 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.

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


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7
Default date returning time in vba intermediate window

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

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 595
Default 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?


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


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Hide Intermediate Levels in Date Dimension Domenick Excel Discussion (Misc queries) 0 December 16th 09 10:09 PM
Complex Time Window / date based calculation stef Excel Worksheet Functions 0 September 10th 07 08:06 PM
formulas using date/time formats returning #value Liesel Excel Discussion (Misc queries) 7 June 20th 06 06:13 AM
Calculating days & time left from start date/time to end date/time marie Excel Worksheet Functions 7 December 7th 05 02:36 PM
clear intermediate window automatically Steven Deng Excel Programming 13 November 1st 04 08:34 AM


All times are GMT +1. The time now is 11:32 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"