我有一份与团队共享的电子表格,我正在寻找一种方法,每次工作表发生变化时,都可以将今天的日期输入到单元格中。我找到了这个代码,它正在工作,但是,我不想弹出消息,我想要今天()插入到单元格 D2 中(我不需要时间,只需要日期)。任何帮助都将不胜感激。
Private Sub Worksheet_Change(ByVal Target As Range)
Dim KeyCells As Range
' The variable KeyCells contains the cells that will
' cause an alert when they are changed.
Set KeyCells = Range("A1:W160")
If Not Application.Intersect(KeyCells, Range(Target.Address)) _
Is Nothing Then
' Display a message when one of the designated cells has been
' changed.
' Place your code here.
MsgBox "Cell " & Target.Address & " has changed."
End If
End Sub