excel date formatting not working

后端 未结 12 3023
-上瘾入骨i
-上瘾入骨i 2021-02-20 15:13

I have an excel sheet created by a 3rd party program.

One of the columns has dates in this format: \"Jan 19, 2015 03:00:00 PM\"

I would like these dates to appea

12条回答
  •  無奈伤痛
    2021-02-20 15:28

    While you didn't tag VBA as a possible solution, you may be able to use what some feel is a VBA shortcoming to your advantage; that being VBA heavily defaulted to North American regional settings unless explicitly told to use another.

    Tap Alt+F11 and when the VBE opens, immediately use the pull down menus to Insert ► Module (Alt+I,M). Paste the following into the pane titles something like Book1 - Module1 (Code).

    Sub mdy_2_dmy_by_Sel()
        Dim rDT As Range
        With Selection
            .Replace what:=Chr(160), replacement:=Chr(32), lookat:=xlPart
            .TextToColumns Destination:=.Cells(1, 1), DataType:=xlFixedWidth, FieldInfo:=Array(0, 1)
            For Each rDT In .Cells
                rDT = CDate(rDT.Value2)
            Next rDT
            .NumberFormat = "dd/mm/yyyy"
        End With
    End Sub
    

    Tap Alt+Q to return to your worksheet. Select all of the dates (just the dates, not the whole column) and tap Alt+F8 to Run the macro.

    Note that both date and time are preserved. Change the cell number format if you wish to see the underlying times as well as the dates.

提交回复
热议问题