Changing YYYYMMDD to MM/DD/YYYY

前端 未结 5 1997
盖世英雄少女心
盖世英雄少女心 2020-12-02 03:09

So I have a date that is 20170529 but whenever I try to format it to a date, the cell just becomes #########. So normally, that means the column width is too small, but even

5条回答
  •  时光说笑
    2020-12-02 03:50

    Select the cells you wish to fix and run this short macro:

    Sub INeedADate()
        Dim r As Range
        For Each r In Selection
            v = r.Text
            If Len(v) = 8 Then
                r.Clear
                r.NumberFormat = "mm/dd/yyyy"
                r.Value = DateSerial(Left(v, 4), Mid(v, 5, 2), Right(v, 2))
            End If
        Next r
    End Sub
    

提交回复
热议问题