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
Apr 07, 2025MVP
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
MHT1974
Apr 09, 2025Copper Contributor
This works a treat now, thx so much Hans for all the help - much appreciated.
All the Best, Markus