I have a column which has date and time of emails from outlook. Some dates are in format - January 2, 2020 4:15 PM
, January-14-20 12:44 PM
, December-24-19 20:15 PM
.
I have tried to use Replace and Substitute functions, Replace does work as defined but from the string time is removed. I would like to have all dates as 2019-12-27 3:02 PM
.
sub Replace()
Dim sString, searchString as String
dim i, LastCell as Long
LastCell = Range("C" & Rows.Count).End(xlUp).Row
Set searchRng = Range("C3:C" & lastCell)
For Each c In searchRng
sString = c
searchString = "-"
If InStr(1, sString, searchString, vbTextCompare) > 0 Then
i = InStr(1, sString, SearchString, vbTextCompare)
i = InStr(i + 1, sString, SearchString, vbTextCompare)
c.Offset(0, 1) = WorksheetFunction.Replace(sString, i, "19", " 2020")
End If
Next c
End Sub