Controlling Automatic Formatting of Dates

by Allen Wyatt
(last updated July 21, 2018)

3

When Ted enters a date with just the month and day, i.e. 4/5, the date displays 5-Apr and the number format is Custom. However, when he enters 4/5/18 the date displays 4/5/2018 and the number format is Date. Ted wonders how he can get the date to format to 4/5/2018 when he enters only 4/5 without having to format the cells to Date before making his entry. In other words, he wants the date to default to Date and not Custom.

There is no way to do this within Excel. In this case, Excel, as part of its parsing process, chooses the date format that it believes you intended based upon how you entered the date. If you want to use a different date format, you must explicitly format the column (or cells) to use the date format you want before you enter the date, or you must format the column (or cells) explicitly after you enter the date.

There is one macro-based solution, but it may be a bit of overkill. All you need to do is to add this event handler to the code window for the worksheet. (Right-click on the worksheet tab and choose View Code from the resulting Context menu. Paste this short macro into the code window that then appears.)

Private Sub Worksheet_Change(ByVal Target As Range)
    If IsDate(Target) Then
        Target.NumberFormat = "m/d/yyyy"
    End If
End Sub

The macro checks whatever you enter into a cell, and if it is determined to be a date (that's the purpose of the IsDate function), then the desired date format is applied to the cell.

I mentioned that this may be a bit of overkill because you will, obviously, need to save the workbook as a macro-enabled workbook. If this is no problem for your use of the workbook, however, then it may solve your date-formatting needs.

Note:

If you would like to know how to use the macros described on this page (or on any other page on the ExcelTips sites), I've prepared a special page that includes helpful information. Click here to open that special page in a new browser tab.

ExcelTips is your source for cost-effective Microsoft Excel training. This tip (13553) applies to Microsoft Excel 2007, 2010, 2013, 2016, 2019, and Excel in Office 365.

Author Bio

Allen Wyatt

With more than 50 non-fiction books and numerous magazine articles to his credit, Allen Wyatt is an internationally recognized author. He is president of Sharon Parq Associates, a computer and publishing services company. ...

MORE FROM ALLEN

Footnotes in Two Columns

When laying out how your printed pages will look, you might want to place your footnotes into more than one column. This ...

Discover More

Displaying a Count of Zeros on the Status Bar

Excel allows you to display the results of several common worksheet functions on the status bar. The available functions ...

Discover More

Entering Data as Thousands

There are many different ways you may need to enter data in a worksheet. For instance, you might want to enter data in ...

Discover More

Solve Real Business Problems Master business modeling and analysis techniques with Excel and transform data into bottom-line results. This hands-on, scenario-focused guide shows you how to use the latest Excel tools to integrate data from multiple tables. Check out Microsoft Excel 2013 Data Analysis and Business Modeling today!

More ExcelTips (ribbon)

Enforcing a Desired Font

If your workbooks are shared and used by a number of different people, you may end up with some formatting in those ...

Discover More

Adjusting Center Across Selection with a Cell Value

One of the most common cell alignment settings I use is the one to center across a selection. If you want to vary how ...

Discover More

Automatically Copying Formatting

It's easy to automatically set the contents of one cell to be equal to another cell. But what if you want to copy the ...

Discover More
Subscribe

FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."

View most recent newsletter.

Comments

If you would like to add an image to your comment (not an avatar, but an image to help in making the point of your comment), include the characters [{fig}] in your comment text. You’ll be prompted to upload your image when you submit the comment. Maximum image size is 6Mpixels. Images larger than 600px wide or 1000px tall will be reduced. Up to three images may be included in a comment. All images are subject to review. Commenting privileges may be curtailed if inappropriate images are posted.

What is 5 + 2?

2018-07-23 13:01:28

Allen

Peter, that would be (to me) the easiest way, but as noted in the original question, Ted wanted a way to accomplish the task "without having to format the cells to Date before making his entry."

-Allen


2018-07-23 11:05:24

Peter Atherton

Just format the column as a long or short date before entering the day & month.


2018-07-22 03:18:52

Jacques Raubenheimer

One other thing that should be mentioned (and adds to the reason why this may be overkill) is that this macro will wipe out the undo stack.


This Site

Got a version of Excel that uses the ribbon interface (Excel 2007 or later)? This site is for you! If you use an earlier version of Excel, visit our ExcelTips site focusing on the menu interface.

Newest Tips
Subscribe

FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."

(Your e-mail address is not shared with anyone, ever.)

View the most recent newsletter.