Date Format

CloudenL

New Member
Joined
Sep 23, 2011
Messages
6
how do i add in when a workbook opens that a specific cell or cells automatically change to a date format (m/dd/yyyy) even if "jan 1 2011" or 1.1.2011 is typed in? is this possible?
 

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).
In the ThisWorkbook module put in a Workbook_Open macro that formats the cell(s) on the specific sheet with a specific numberformat. For example:

Code:
Private Sub Workbook_Open()
    With Sheets("Sheet1")
        .Range("A5").NumberFormat = "MM-DDD-YYYY"
        .Range("E:E").NumberFormat = "MM-DDD-YYYY"
    End With
End Sub
 
Upvote 0
Thank You, that worked, one additional question though. what if someone types it in as Jan 1, 2011, will it automatically convert it to the poper format? it doesnt seem to be working, so not sure if i am doing something incorrect in the spreadsheet itself under the formatting there, or does this code make the original formatting i did go away?
 
Upvote 0
Once a cell has been formatted with a specific TIME/DATE number format, you shouldn't be able to easily trick Excel. It's pretty good at spotting a date "string" and converting it to date/format if the cell is already formatted as such. But it's not impossible.

If I type this:

Jan 1, 2011
Jan1, 2011


...Excel converts that properly to the date format already applied to the cell. But if I type this:

Jan1,2011
Jan 1,2011


...it won't. It just reads that as a text string.
 
Upvote 0

Forum statistics

Threads
1,224,521
Messages
6,179,289
Members
452,902
Latest member
Knuddeluff

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