SBF12345

Well-known Member
Joined
Jul 26, 2014
Messages
614
Greetings,

I have a I column of values of the format " Aug 30, 2018" and so on. I would like to be able to convert these into the format "MM/DD/YYYY"

Code:
Dim A as Long, LastRow as Long
LastRow = Cells(Rows.Count,"A").End(xlUp).Row
For K = LastRow to 1 Step -1
CDate(Cells(K,"A").value) = Cells(K,"A").Value
Next K

I am receiving a syntax error on the CDate line. How can I correctly write this code?
 

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.
It should be
Code:
Cells(K,"A").value = Cdate(Cells(K,"A").Value)

Check Dim A as Long as well
 
Upvote 0
CDATE() converts a string value to a numeric. If the cells are strings, then CDATE() should be right side of equality sign. In either case, the number format will need to be set. A1 is usually a text field.

Uncomment the lines if they are string values.
Code:
Sub Main()
    'Dim A As Long, LastRow As Long
    'LastRow = Cells(Rows.Count, "A").End(xlUp).Row
    'For K = LastRow To 1 Step -1
    '    Cells(K, "A") = CDate(Cells(K, "A"))
    'Next K
    Range("A1", Cells(Rows.Count, "A").End(xlUp)).NumberFormat = "MM/DD/YYYY"
End Sub
 
Upvote 0
Cells(K,"A").value = CDate(Cells(K,"A").Value)
and pay attention to the cell format.
 
Upvote 0

Forum statistics

Threads
1,213,532
Messages
6,114,177
Members
448,554
Latest member
Gleisner2

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