Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/vba/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
VB Excel的新功能_Excel_Vba - Fatal编程技术网

VB Excel的新功能

VB Excel的新功能,excel,vba,Excel,Vba,我试图根据下面的代码在我的工作表中更改几列,但是我一直收到一个错误代码 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

我试图根据下面的代码在我的工作表中更改几列,但是我一直收到一个错误代码

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

进行了一次疯狂的尝试,但我认为您希望将其格式化如下

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

您收到的错误是什么?日期是什么?什么是时间?我怀疑这实际上是一个关于Excel中VBA的问题,而不是关于VB.NET的问题。如果这是真的,请修复标签。很抱歉,我更改了标签。我在同一张工作表上有两列,当每列单独更新时,日期和时间都记录在这些单元格旁边的列中