Passing Excel formats in VBA date variables

E

ExcelMonkey

I have a start date in my spreadsheet model that is formatted as follow
(m/d/yyyy h:mm). I have named the cell "xlStartDate" I have a VB
variable that is called StartDate. I pass the excel variable to th
vba variable

Dim StartDate As Date
StartDate = Range("xlStartDate")


When I put my cursor over teh StartDate varible it says 01/01/2004.
Why does it not have the formatting of m/d/yyyy h:mm
 
R

Rob van Gelder

ExcelMonkey,

StartDate is just a date variable. It contains a date and that's all - no
formatting.
The format in the tooltip you're seeing is a format defined by your regional
settings.
 
E

ExcelMonkey

If I want to format it do I use a format function or a format method o
the vba variable
 
R

Rob van Gelder

Yes, you would use the format function when you wanted to show the date as a
string.
eg.

Sub test()
Dim dtmTemp As Date

dtmTemp = Now()

MsgBox dtmTemp 'automatically formats as defined by regional settings

MsgBox Format(dtmTemp, "dd-Mmm-yyyy HH:mm")
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top