在VBA excel中更改日期格式

在VBA excel中更改日期格式,vba,excel,date,format,Vba,Excel,Date,Format,我一直在研究一个将日期从DD-MM-YY更改为DD-MM-YYYY的宏,我想知道是否可以创建一个可重复的宏来检查日期列,如果它找到任何DD-MM-YY日期,它会自动将这些日期更改为DD-MM-YYYY尝试。NumberFormat: Sub format_date() Dim date_column As Range With ActiveSheet With .Cells Set date_column = .Find(What:="date", LookIn:=xlF

我一直在研究一个将日期从DD-MM-YY更改为DD-MM-YYYY的宏,我想知道是否可以创建一个可重复的宏来检查日期列,如果它找到任何DD-MM-YY日期,它会自动将这些日期更改为DD-MM-YYYY

尝试
。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

没有必要检查。只需选择要格式化的列,并将DD-MM-YYYY格式应用于所有单元格。Tank u warner!在我得到的数据中,日期被写为yy/mm/dd。看起来它是以数字形式写的,而不是实际的日期格式。我们试图将其从年月日“翻转”到年月日,但上面的宏没有找到日期格式,而是直接转到messagebox