ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Trigger Macro on change in cell value (https://www.excelbanter.com/excel-programming/359781-trigger-macro-change-cell-value.html)

qwerty[_2_]

Trigger Macro on change in cell value
 
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?



JE McGimpsey

Trigger Macro on change in cell value
 
Use the Worksheet_Change() event macro. See

http://cpearson.com/excel/events.htm

In article ,
"qwerty" wrote:

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?


qwerty[_2_]

Trigger Macro on change in cell value
 
OK - works perfectly for one cell. What is the most efficient way for
multiple cells?

"JE McGimpsey" wrote in message
...
Use the Worksheet_Change() event macro. See

http://cpearson.com/excel/events.htm

In article ,
"qwerty" wrote:

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?




JE McGimpsey

Trigger Macro on change in cell value
 
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



In article ,
"qwerty" wrote:

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



All times are GMT +1. The time now is 04:23 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com