Arty Choke
New Member
- Joined
- Oct 7, 2009
- Messages
- 9
I created a worksheet with the following code to cause a macro to execute when the values in certain cells change:
Private Sub Worksheet_Change(ByVal Target As Range)
'Check to see that we have enabled auto macro updating
If Range("Report_Type_Auto_Run_Macros") = "ENABLED" Then
'Remember which cell I started on, so I can return there
Starting_Cell = ActiveCell.Address
'Turn off ALL events so the sub does not put the code into a loop.
Application.EnableEvents = False
'Hide and Unhide Rows - Did we change something warranting a Row Hide / Unhide update?
'******
If Not Intersect(Target, Range("Report_Type_Row_Flags", "Report_Type_Selected")) Is Nothing Then
Call Hide_and_Unhide_Rows_and_Columns
End If
'Turn on ALL events
Application.EnableEvents = True
'Return to the cell I started on
Range(Starting_Cell).Select
End If
End Sub
I noticed that this macro responded to more cells than I intended (cells outside of the named ranges). I determined that I had made an error in th e line following "******". I had enclosed each named ranged in its own pair of quote marks. They should have both been grouped within a single pair of quote marks. I changed that line as follows:
If Not Intersect(Target, Range("Report_Type_Row_Flags, Report_Type_Selected")) Is Nothing Then
The code now only responds to changes in the named ranges, however, it also only responds when I physically enter new data into the cell. It no longer responds when the formulas in those cells cause the values to change. (It used to respond to either type of change, in the original version.)
How do I cause a Worksheet_Change event to react when the value in a cell changes as a result of a formula?
Thanks!
Arty
Private Sub Worksheet_Change(ByVal Target As Range)
'Check to see that we have enabled auto macro updating
If Range("Report_Type_Auto_Run_Macros") = "ENABLED" Then
'Remember which cell I started on, so I can return there
Starting_Cell = ActiveCell.Address
'Turn off ALL events so the sub does not put the code into a loop.
Application.EnableEvents = False
'Hide and Unhide Rows - Did we change something warranting a Row Hide / Unhide update?
'******
If Not Intersect(Target, Range("Report_Type_Row_Flags", "Report_Type_Selected")) Is Nothing Then
Call Hide_and_Unhide_Rows_and_Columns
End If
'Turn on ALL events
Application.EnableEvents = True
'Return to the cell I started on
Range(Starting_Cell).Select
End If
End Sub
I noticed that this macro responded to more cells than I intended (cells outside of the named ranges). I determined that I had made an error in th e line following "******". I had enclosed each named ranged in its own pair of quote marks. They should have both been grouped within a single pair of quote marks. I changed that line as follows:
If Not Intersect(Target, Range("Report_Type_Row_Flags, Report_Type_Selected")) Is Nothing Then
The code now only responds to changes in the named ranges, however, it also only responds when I physically enter new data into the cell. It no longer responds when the formulas in those cells cause the values to change. (It used to respond to either type of change, in the original version.)
How do I cause a Worksheet_Change event to react when the value in a cell changes as a result of a formula?
Thanks!
Arty