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

How to create a cell-sized chart?
Tiny charts, called Sparklines, were added to Excel 2010. Look for Sparklines on the Insert tab.
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")
 
Upvote 0
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")
 
Upvote 0
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
 
Upvote 0

Forum statistics

Threads
1,214,839
Messages
6,121,891
Members
449,058
Latest member
Guy Boot

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
Back
Top