这是一个仅针对单元格 A2/J2 的示例。如果您想在整个范围内使用它,则必须扩展代码。下面的代码进入工作表的“Worksheet_Change”过程。部分示例来自微软
Private Sub Worksheet_Change(ByVal Target As Range)
Dim KeyCells As Range
'Code Example from Microsoft.com
'http://support.microsoft.com/kb/213612
' The variable KeyCells contains the cells that will
' cause an alert when they are changed.
Set KeyCells = Range("A2:H20")
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." <--- Original Microsoft Example
'Code to Check Value/Status of A2
If Target.Address = "$A$2" Then
If Range("A2").Value <> "" Then
Range("J2").Value = Now()
Else
Range("J2").Value = ""
End If
End If
End If
End Sub