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
 

Some videos you may like

Excel Facts

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.

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
 

Watch MrExcel Video

Forum statistics

Threads
1,122,511
Messages
5,596,581
Members
414,079
Latest member
Frills

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