【问题标题】:Changing Date format in VBA-excel在 VBA-excel 中更改日期格式
【发布时间】:2018-04-30 14:34:03
【问题描述】:

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

【问题讨论】:

  • 无需检查。只需选择要设置格式的列,然后将 DD-MM-YYYY 格式应用于所有单元格。

标签: vba excel date format


【解决方案1】:

试试.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

【讨论】:

  • 坦克你华纳!在我提供的数据中,日期已写为 yy/mm/dd。看起来它是以数字形式写入的,而不是实际的日期格式。我们正在尝试将其从 yy-mm-dd “翻转”为 dd-mm-yyyy,但上面的宏没有找到日期格式,而是直接进入消息框
猜你喜欢
  • 1970-01-01
  • 2012-03-14
  • 1970-01-01
  • 2014-10-23
  • 1970-01-01
  • 2021-06-05
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多