Trigger Macro on change in cell value

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?
 
Q

qwerty

OK - works perfectly for one cell. What is the most efficient way for
multiple cells?
 
J

JE McGimpsey

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top