Ironvine Analytics Web Analytics, Data Analysis, Online Marketing, and Search Engine Information.

23Dec/10Off

Excel VBA – Convert Text to Date

This is a quick little Excel VBA macro to convert a date in text format into an actual date format.

This can be easily modified for other string formats as needed.

Sub ConvertToDate()

'=======Convert "yyyymmdd" text format to "yyyymmdd" date format=======

For Each cell In Selection.Cells

s = cell.Value

If s = "" Then
Else
cell.Value = (Left(Trim(s), 4) & "/" & Mid(s, 5, 2) & "/" & Mid(s, 7, 2))
cell.NumberFormat = "yyyymmdd"
End If

Next

End Sub