我一直在研究一个宏,它将日期从DD-MM-YY更改为DD-MM-YYYY,我想听听是否可以创建一个可重复的宏,检查日期列,如果它找到任何DD-MM-YY日期,它会自动将它们更改为DD-MM-YYYY
答案 0 :(得分:0)
尝试.NumberFormat
:
Sub format_date()
Dim date_column As Range
With ActiveSheet
With .Cells
Set date_column = .Find(What:="date", LookIn:=xlFormulas, _
LookAt:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=True, SearchFormat:=False)
End With
If date_column Is Nothing Then
MsgBox "Cant find date column", vbCritical
Exit Sub
End If
With date_column.EntireColumn
.NumberFormat = "mm/dd/yyyy;@"
End With
End With
End Sub