Trigger Macro on change in cell value

  • Thread starter Thread starter qwerty
  • Start date Start date
Q

qwerty

In my data validation I put the minimum and maximum values in the
spreadsheet rather than hard code them. The problem is if the end user
changes the minimum or maximum value I want to run a macro to reset the
messages to be displayed by the data validation message box.

What I want to do is trigger the macro if either value changes. Cell M8
holds the minimum, N8 holds the maximum value. Value is integer. So if
either of these numbers are change, how do I automatically run my macro?
 
Depends -

If the same action will occur for all cells, one way:

Private Sub Worksheet_Change(ByVal Target As Excel.Range)
With Target
If Not Intersect(.Cells, Range("A1, B2")) Is Nothing Then
'do stuff here
End If
End With
End Sub

If different things should occur when each cell is changed, one way:

Private Sub Worksheet_Change(ByVal Target As Excel.Range)
With Target
Select Case .Cells.Address(False, False)
Case "A1"
'Do A1 Stuff
Case "B2"
'Do B2 Stuff
Case Else
'Do Nothing
End Select
End With
End Sub
 
Back
Top