【问题标题】:Excel macro vba scriptExcel宏vba脚本
【发布时间】:2015-06-13 14:33:09
【问题描述】:

我正在尝试格式化 excel 表中的列,其中常规格式日期时间到日期选项不起作用,因为我从 clear quest 中导出了 excel 中的数据。我需要 mm/dd/yyyy 格式的日期列,还有一个可以执行此操作的 VB 脚本。

【问题讨论】:

标签: excel vba macos


【解决方案1】:
Sub DateFormat()
     Range("C2:C64").NumberFormat = "mm/dd/yyyy"
End Sub

【讨论】:

  • 如果只有一列 C 范围 C2:C64 代码将如何?
  • @user803860 - 将 "Columns("G:G").Select" 更改为 "Range("C2:C64").Select"
  • Sub DateFormat() ' '将 G:G 更改为您要更改的列 ' Columns("C2:C64").Select Selection.NumberFormat = "mm/dd/yyyy " Range("C2").Select End Sub
  • @user803860 - 您必须将“列”更改为“范围”......或者,在我对答案进行编辑后使用新代码。
  • @user803860 - 这是否满足您的需求?如果是,请标记为已回答。如果没有,请告诉我你看到了什么。谢谢:)
【解决方案2】:

根据这篇文章:Excel VBA date formats

Function CellContentCanBeInterpretedAsADate(cell As Range) As Boolean
    Dim d As Date
    On Error Resume Next
    d = CDate(cell.Value)
    If Err.Number <> 0 Then
        CellContentCanBeInterpretedAsADate = False
    Else
        CellContentCanBeInterpretedAsADate = True
    End If
    On Error GoTo 0
End Function

【讨论】:

    猜你喜欢
    • 2014-11-20
    • 1970-01-01
    • 2011-01-14
    • 1970-01-01
    • 2013-07-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-02-17
    相关资源
    最近更新 更多