[VBA] Detecting changes in cell
The
Event Change feature of a sheet will detects the change in the active cell but it gives no information about the content.
The example given below will help you to find out if the cell was changed, if it still works after being initialized or amended.
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Static AncAdress As String, AncCell As Variant
If AncAdress <> "" Then 'for first initialization.
If AncCell <> Range(AncAdress) Then
'The cell that you just left has been changed.
'Put action to be taken.
Stop
End If
End If
AncAdress = Target.Address
AncCell = Target.Value2
End Sub
Note that:
When the
event change is activated, the contents of the cell that has just been selected to be in
Target. but the module above the test the cell that has been left.