JSBach
JSBach

Reputation: 4747

Format a generic cell to date

I've just imported an CSV into Excel. Everything looks nice, but there are no formatted columns. One of the columns contains values in the format YYYYMMDD (for instance 20120102 for Jan 2nd 2012). Is there any way that I can format the cell so it automatically transforms this text into a date? I would not like to create a new column.

Upvotes: 0

Views: 200

Answers (1)

Gary's Student
Gary's Student

Reputation: 96781

Select your values and run this small macro:

Sub MakeDates()
    For Each r In Selection
        v = r.Text
        r.Value = DateSerial(Mid(v, 1, 4), Mid(v, 5, 2), Right(v, 2))
    Next r
End Sub

Upvotes: 2

Related Questions