Cadman
Cadman

Reputation: 81

VBA Date Format - month/day/year

I want to produce todays date like this: 01/23/2016 month/day/year. I wrote the below code but the result is 23/01/2016. Can anyone help me? Thanks

ActiveSheet.Cells(1, 2) = Format(Date, "mm/dd/yyyy")

Upvotes: 4

Views: 1939

Answers (1)

teylyn
teylyn

Reputation: 35915

The code you use enters something into an Excel cell. Excel recognises that it is a date and will display the date according to the default settings.

In order to display the date with your preferred format, you need to format the cell that displays the date, not the data entry string.

ActiveSheet.Cells(1, 2) = Date
ActiveSheet.Cells(1, 2).NumberFormat = "mm/dd/yyyy"

Upvotes: 9

Related Questions