简体   繁体   中英

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")

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"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM