Macro to change text format to date format

ThomasA83

Board Regular
Joined
Mar 10, 2009
Messages
95
Hey,

Have a problem with my huge file with data. In column J I have dates, like 2010-10-13, but the format of the dates is text.
Do anyone know how to make a macro to convert the entire column J into date format, and should read "13-10-2010". If I go to each cell in column J, press F2 and enter, the field automatically changes to date format, but for 16000 rows, its gonna take me alot of time.

Brgds
Thomas
 

Excel Facts

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple
Try...

Code:
Sub ToDate()
    Dim c As Range
    For Each c In Range("J2:J" & Range("J" & Rows.Count).End(xlUp).Row)
        c.Value = CDate(c.Value)
    Next c
End Sub

Once done, you can adjust the format.

Denis
 
Upvote 0
Try selecting the dates, Data > Text to Columns, click Next twice, tick Date and select YMD then click Finish.
 
Upvote 0
Combining suggestions in posts #2 and #3 above you get:

Code:
Sub ConvDates()
Columns("J:J").TextToColumns Destination:=Range("J1"), DataType:=xlDelimited, _
        TextQualifier:=xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=True, _
        Semicolon:=False, Comma:=False, Space:=False, Other:=False, FieldInfo _
        :=Array(1, 5), TrailingMinusNumbers:=True
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,392
Messages
6,119,254
Members
448,879
Latest member
oksanana

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top