VB-VB Excel新手

时间:2014-01-07 19:18:40

标签: excel-vba vba excel

我正在尝试根据以下代码在我的工作表中更改几列,但是我一直收到错误代码。

Private Sub Worksheet_Change(ByVal Target As Range)
    If Target.Column = 12 Then
        Application.EnableEvents = False
        Cells(Target.Row, 13).Value = Date + Time
        Application.EnableEvents = True
    End If
    If Target.Column = 13 Then
        Application.EnableEvents = False
        Cells(Target.Row, 14).Value = Date + Time
        Application.EnableEvents = True
    End If
End Sub

1 个答案:

答案 0 :(得分:0)

采取疯狂的刺,但我假设你想格式化如下

Private Sub Worksheet_Change(ByVal Target As Range)
    If Target.Column = 12 Then
    Application.EnableEvents = False
    Cells(Target.Row, 13).Value = Format(DateTime.Now, "mm/dd/yyyy")
    Application.EnableEvents = True
    End If
    If Target.Column = 13 Then
    Application.EnableEvents = False
    Cells(Target.Row, 14).Value = Format(DateTime.Now, "hh:mm:ss")
    Application.EnableEvents = True
    End If
End Sub