I'm working on my team metrics. I receive a bunch of incidents with the corresponding dates and times in the US format (mm/dd/yyyy HH:MM:SS)
For some reason, when I move the data from the cvs file to the xls I work, it modify all dates over the 13th.
I have been working this manually to get mm/dd/yyyy. But when I tried to move the manual steps to a macro it mess the formatting again
Sub date_formatting4()
'
' date_formatting4 Macro
'
'
Range("B2:B106").Select
Selection.Copy
ActiveWindow.SmallScroll Down:=-131
Range("M2").Select
ActiveSheet.Paste
Columns("B:C").Select
Application.CutCopyMode = False
Selection.Clear
Columns("M:M").Select
Selection.TextToColumns Destination:=Range("M1"), DataType:=xlFixedWidth, _
FieldInfo:=Array(Array(0, 1), Array(10, 1), Array(25, 1)), TrailingMinusNumbers _
:=True
Columns("N:N").Select
Selection.Delete Shift:=xlToLeft
Columns("M:M").Select
Selection.NumberFormat = "@"
Range("O2").Select
Selection.Formula = "=IF(ISNUMBER(M2),DATE(YEAR(M2),DAY(M2),MONTH(M2)),DATE(RIGHT(M2,4),LEFT(M2,2),MID(M2,4,2)))"
Selection.AutoFill Destination:=Range("O2:O106"), Type:=xlFillDefault
Range("O2:O106").Select
Selection.NumberFormat = "mm/dd/yyyy"
ActiveWindow.SmallScroll Down:=82
Selection.Copy
ActiveWindow.SmallScroll Down:=-102
Range("B2").Select
Selection.PasteSpecial Paste:=xlPasteValuesAndNumberFormats, Operation:= _
xlNone, SkipBlanks:=False, Transpose:=False
Range("B1").Select
Application.CutCopyMode = False
ActiveCell.FormulaR1C1 = "Open Time"
Range("C1").Select
ActiveCell.FormulaR1C1 = "Monthly"
Range("O2:O106").Select
Selection.NumberFormat = "mm/yyyy"
Selection.Copy
Range("C2").Select
Selection.PasteSpecial Paste:=xlPasteValuesAndNumberFormats, Operation:= _
xlNone, SkipBlanks:=False, Transpose:=False
Columns("L:P").Select
Application.CutCopyMode = False
Selection.Delete Shift:=xlToLeft
Range("L3").Select
End Sub
Basically the script do the same I do manually:
- Copy the dates to an aux column
- Using Text to columns, remove the time
- Change the format to text
- Use the formula to get the dates
- Clean the format from the destination
- Change the format to get mm/dd/yyyy
- Copy the data
- Remove the aux columns
I don't know VBA language to script the macro, so I used the auto recording from excel.
I have attached a test spreadsheet I have using.
test formats.xlsx
Any help will be appreciate
Bookmarks