Forum Discussion
MHT1974
Mar 24, 2025Copper Contributor
VBA to convert MMM DD YYYY to date
Hi All, I am looking for an Excel VBA code that would e.g. check in Col D if the date is already in date format and if not convert it from text to date format and repeat this for all populated cell...
- Apr 07, 2025
Thank you. Try this:
Sub Convert2Date() Dim rng As Range Dim cel As Range Application.ScreenUpdating = False On Error Resume Next Set rng = Range(Range("D2"), Range("D" & Rows.Count).End(xlUp)) rng.NumberFormat = "m/d/yyyy" For Each cel In rng cel.Value = CDate(cel.Value) Next cel Application.ScreenUpdating = True End Sub
HansVogelaar
Mar 24, 2025MVP
Sub Test()
Dim rng As Range
Dim parts() As String
Application.ScreenUpdating = False
For Each rng In Range(Range("D2"), Range("D" & Rows.Count).End(xlUp))
If Application.IsText(rng.Value) Then
parts = Split(rng.Value)
If UBound(parts) > 0 Then
rng.Value = DateValue(parts(1) & "-" & parts(0) & "-" & parts(2))
Else
parts = Split(rng.Value, "/")
If UBound(parts) > 0 Then
rng.Value = DateSerial(parts(2), parts(1), parts(0))
End If
End If
End If
Next rng
Application.ScreenUpdating = True
End SubMHT1974
Mar 25, 2025Copper Contributor
Good morning Hans, thx so much for the speedy response.
When testing this I get a Run Time Error '13', see below
And here's a snippet of what the spreadsheet Col D looked like before running the VBA.
Would appreciate any further advise pls