Forum Discussion
metertreater
May 06, 2022Copper Contributor
Convert displayed date to mm/yyyy format, and convert that to text
I am attempting to shorten my keystroke times for data entry of several hundred dates. First, I need to convert the number format of six digits (ex: 072012) or five digits (ex: 72012) to display mm/...
HansVogelaar
May 06, 2022MVP
The format doesn't really matter - a date is a date regardless of how it is displayed.
So it is sufficient to convert the values to 'real' dates. After importing them into Access, apply the custom format mm/yyyy there.
Here is a macro. Select the range with the values to be converted before you run the macro.
Sub Num2Date()
Dim rng As Range
Dim s As String
Application.ScreenUpdating = False
For Each rng In Selection
s = rng.Value
rng = DateSerial(Right(s, 4), Left(s, Len(s) - 4), 1)
Next rng
Selection.EntireColumn.AutoFit
Application.ScreenUpdating = True
End Sub
- metertreaterMay 06, 2022Copper Contributor
Thank you, Hans.
Now, would I use that macro in Excel prior to the import, or is it used afterwards in Access?
- HansVogelaarMay 06, 2022MVP
This is a macro to be run in Excel.
- metertreaterMay 06, 2022Copper ContributorI'll try it out. thank you