Entering dates in vba inputbox as ddmmyy. Excel returns mmddyy

P

pkeegs

I am using an inputbox in VBA to return a date into an excel cell. When I
enter the date as dd mm yy, excel returns it as mm dd yy, irrespective of how
I have formatted the receiving cell. It only applies to the lower numbers
such as 06/07/05. If I were to enter 25/07/05, it would return correctly.
 
B

Bob Phillips

You must be in the UK or Europe.

In VBA, all dates are treated as US style dates. Obviously, 25/07/2005 is
unambiguous, but 06/07/2005 isn't, so VBA treats it as US style.

You can force it rather than use the VBA default date casting, using CDate,
example

activecell.Value = cdate(inputbox("Input date"))


--

HTH

RP
(remove nothere from the email address if mailing direct)
 
P

pkeegs

Thanks Bob, that was spot-on

Bob Phillips said:
You must be in the UK or Europe.

In VBA, all dates are treated as US style dates. Obviously, 25/07/2005 is
unambiguous, but 06/07/2005 isn't, so VBA treats it as US style.

You can force it rather than use the VBA default date casting, using CDate,
example

activecell.Value = cdate(inputbox("Input date"))


--

HTH

RP
(remove nothere from the email address if mailing direct)
 

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