Date changes

Melody Rich

New Member
Joined
Dec 13, 2022
Messages
2
Office Version
  1. 365
Platform
  1. Windows
I have the cell formatted for date 3/14/12. When I enter a date "01/15/22", the displayed date is "07/18/31". How can I get this cell to display the date that I enter without adding "/" between numbers?
Thank you
 

Excel Facts

Create a Pivot Table on a Map
If your data has zip codes, postal codes, or city names, select the data and use Insert, 3D Map. (Found to right of chart icons).
Welcome to the Board!

It is important to understand how Excel stores dates. It actually stores them as numbers, specifically the number of days since 1/0/1900.
So dates are really just numbers with special date formats.
The value 11522 translates to date 7/18/31, which is why you are seeing that.

If you want it to convert it over to a date according to your specifications, you can use this VBA code, which will run automatically upon manual cell entry.
Right-click on the sheet tab name at the bottom of the screen, select "View Code" and paste this VBA code in the resulting VB Editor window:
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)

    Dim d As String

    If Target.CountLarge > 1 Then Exit Sub

'   Fix entry if in column 1
    If Target.Column = 1 Then
        Application.EnableEvents = False
        d = Format(Target, "000000")
        Target = DateSerial(Right(d, 2), Left(d, 2), Mid(d, 3, 2))
        Application.EnableEvents = True
    End If
    
End Sub
I wrote this code to fix any entry made into column A as it happens, but we can change the range to whatever range you want to apply it to.
 
Upvote 0
Welcome to the Board!

It is important to understand how Excel stores dates. It actually stores them as numbers, specifically the number of days since 1/0/1900.
So dates are really just numbers with special date formats.
The value 11522 translates to date 7/18/31, which is why you are seeing that.

If you want it to convert it over to a date according to your specifications, you can use this VBA code, which will run automatically upon manual cell entry.
Right-click on the sheet tab name at the bottom of the screen, select "View Code" and paste this VBA code in the resulting VB Editor window:
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)

    Dim d As String

    If Target.CountLarge > 1 Then Exit Sub

'   Fix entry if in column 1
    If Target.Column = 1 Then
        Application.EnableEvents = False
        d = Format(Target, "000000")
        Target = DateSerial(Right(d, 2), Left(d, 2), Mid(d, 3, 2))
        Application.EnableEvents = True
    End If
   
End Sub
I wrote this code to fix any entry made into column A as it happens, but we can change the range to whatever range you want to apply it to.
Thank you
 
Upvote 0
You are welcome.

Did that work out for you?
Do you need help making changes to the range?
 
Upvote 0

Forum statistics

Threads
1,214,642
Messages
6,120,701
Members
448,980
Latest member
CarlosWin

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