简体   繁体   中英

Changing YYYYMMDD to MM/DD/YYYY

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 when I extend the column, it just shows #####

How do I convert these to dates.

A quick method would be Data, Text-to-Columns, Fixed Width, Date: YMD, Finish. The following is for all intents and purposes in real-time.

在此处输入图片说明

Shouldn't take too much to record that into a sub procedure.

从格式单元格中选择,从类别中选择日期,然后选择所需的类型

=DATEVALUE(TEXT(A1,"0000\/00\/00"))

并将结果格式化为日期

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

I had the same problem. I used "Gary's Student's" answer. You have to press ALT+F11 and just copy and paste, then close that window. Then you select the cells you want to change, go to VIEW tab, on the far right is macros, hit view macros and select the one that says "INeedADate"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM