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的问题。如果这是真的,请修复标签。很抱歉,我更改了标签。我在同一张工作表上有两列,当每列单独更新时,日期和时间都记录在这些单元格旁边的列中