Skip to content

Instantly share code, notes, and snippets.

@lporras
Last active October 19, 2019 20:53
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lporras/3c27740fd5ef4963cf825641e6f44e36 to your computer and use it in GitHub Desktop.
Save lporras/3c27740fd5ef4963cf825641e6f44e36 to your computer and use it in GitHub Desktop.
How to run a macro when certain cells change in Excel
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:C10")
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment