📅  最后修改于: 2022-03-11 14:51:53.910000             🧑  作者: Mango
Option Explicit
Sub stripTime()
Dim i As Integer
With Worksheets("Sheet1")
'check to see if A1 is a date or a column text label
i = Abs(Not IsDate(.Cells(1, 1).Value))
With .Range(.Cells(1 + i, "A"), .Cells(.Rows.Count, "A").End(xlUp))
.TextToColumns Destination:=.Cells(1, "C"), DataType:=xlFixedWidth, _
FieldInfo:=Array(Array(0, xlDMYFormat), Array(10, xlSkipColumn))
'optionally assign a custom number format
.Offset(0, 2).NumberFormat = "[color10]dd-mmm-yyyy_)"
'optionally autofit the column width
.Offset(0, 2).EntireColumn.AutoFit
End With
End With
End Sub