Hi,
I have a few columns E,X and Z with the dates in the form of 20120426 and I need to convert it to 04/26/2012 format using VBA in Excel 2003.
Any help is appreciated.
Thanks,
David
Hi,
I have a few columns E,X and Z with the dates in the form of 20120426 and I need to convert it to 04/26/2012 format using VBA in Excel 2003.
Any help is appreciated.
Thanks,
David
Last edited by djfscouse; 10-25-2012 at 11:19 AM. Reason: Forgot to mention in Excel 2003
David,
Give this a try:
Sub tgr() Dim rngArea As Range Dim lCalc As XlCalculation With Application lCalc = .Calculation .Calculation = xlCalculationManual .EnableEvents = False .ScreenUpdating = False End With On Error GoTo CleanExit For Each rngArea In Range("E:E,X:X,Z:Z").SpecialCells(xlCellTypeConstants).Areas With rngArea If .NumberFormat <> "mm/dd/yyyy" Then .Value = Evaluate("If(IsNumber(" & .Address & "),--Text(" & .Address & ",""0000\/00\/00"")," & .Address & ")") .NumberFormat = "mm/dd/yyyy" End If End With Next rngArea CleanExit: With Application .Calculation = lCalc .EnableEvents = True .ScreenUpdating = True End With If Err.Number <> 0 Then MsgBox Err.Description, , "Error: " & Err.Number Err.Clear End If Set rngArea = Nothing End Sub
Hope that helps,
~tigeravatar
Forum Rules: How to use code tags, mark a thread solved, and keep yourself out of trouble
Thanks tigeravatar,
But unfortunately it did not work, here is an example to the data in xls file.
Thanks,
David
djfscouse,
From your original post:
However, your provided example file has the dates in columns E, Y, and AA. The macro is easy enough to adjust though:
'Change this line For Each rngArea In Range("E:E,X:X,Z:Z").SpecialCells(xlCellTypeConstants).Areas 'To be this instead For Each rngArea In Range("E:E,Y:Y,AA:AA").SpecialCells(xlCellTypeConstants).Areas
Thanks again tigeravatar, sorry for the original info.
Another way:
http://www.youtube.com/watch?v=HnphWTpmV8Y
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks