VBA Date formatting problem, please help

Data Head

New Member
Joined
Mar 25, 2009
Messages
2
Hi Folks,

I'm trying to format a cell to show a date as 04 Jan 2009

..so I setup a subroutine as...
-----------------------
Columns("A:A").Select
Selection.NumberFormat = "dd mmm yyyy"
Cells(1, 1).Value = "04/01/2009" ' yes, my PC is set to English settings!
------------------------
...BUT, when it runs, the cell entry appears as 01 Apr 2009

If I type 04/01/2009 directly into the cell on the worksheet, then press return, it displays the date as 04 Jan 2009...which is what I wanted!!!

Please help, it's driving me crazy!

DH
 

Excel Facts

Links? Where??
If Excel says you have links but you can't find them, go to Formulas, Name Manager. Look for old links to dead workbooks & delete.

Mike Blackman

Well-known Member
Joined
Jun 8, 2007
Messages
2,494
Hi and welcome to the board,

Try entering it into the VBE in MDY Format or alternatively try;

Code:
Cells(1, 1) = Format("04/01/2009", "dd mmm yy")
 

Andrew Poulsom

MrExcel MVP
Joined
Jul 21, 2002
Messages
73,092
VBA always uses US style dates when coercing a string, but its DateValue function is locale aware:

Cells(1, 1).Value = DateValue("04/01/2009")
 

Data Head

New Member
Joined
Mar 25, 2009
Messages
2
Much thanks folks!

Andrew's Cells(1, 1).Value = DateValue("04/01/2009") is the more universal method ( I don't know what the user's PC setup is), so I'll use that.

Thanks again!!!
DH
 
Master Excel Bundle

Excel contains over 450 functions, with more added every year. That’s a huge number, so where should you start? Right here with this bundle.

Forum statistics

Threads
1,167,651
Messages
5,854,959
Members
431,689
Latest member
jacker01

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top