Worksheet change event to triger only if a specific cell value changes

hrayani

Well-known Member
Joined
Jul 23, 2010
Messages
1,516
Office Version
  1. 2016
Platform
  1. Windows
Hi friends,

I am using the below code to hide unhide rows based

Code:
Private Sub Worksheet_Change(ByVal Target As Range)

    
   ActiveSheet.Unprotect
    
    ActiveWorkbook.UpdateLink Name:= _
        "\\192.168.0.100\itex Share\ITEX\DATA ENTRY.xlsm", Type:=xlExcelLinks
      
    Dim xRg As Range
    Application.ScreenUpdating = False
        For Each xRg In Range("A23:A52,A61:A85")
            If xRg.Value = True Then
                xRg.EntireRow.Hidden = False
         
            Else
                xRg.EntireRow.Hidden = True
               
            End If
        Next xRg
        
       
       
                                
    ActiveSheet.Protect DrawingObjects:=False, Contents:=True, Scenarios:= _
    False, AllowFormattingCells:=True, AllowFormattingColumns:=True, _
    AllowFormattingRows:=True




End Sub

The problem is the code triggers every time a change is made to the sheet.
Can we just set the code to trigger only when a specific cell is changed.
In my case its cell E17


Regards,

Humayun
 

Excel Facts

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"
You can't stop the code triggering when any change is made, but you can make it so that the actions in your code are only processed if E17 is changed.
Rich (BB code):
Private Sub Worksheet_Change(ByVal Target As Range)

  If Not Intersect(Target, Range("E17")) Is Nothing Then
  
    'rest of your code here

  End If

End Sub
 
Upvote 0
Thanks Peter,

Works Perfect....

Though I don't need it right now but would like to ask for my knowledge that how to add some more cells besides E17..
Like if i want the code to trigger if either E17 or J1 changes....
 
Upvote 0
Try altering the "If... " line
Code:
If Not Intersect(Target, Range("E17, J30, P40")) Is Nothing Then
 
Last edited:
Upvote 0
I tried myself to add a second cell

Code:
If Not Intersect(Target, Range("E17:E17,J1:J1")) Is Nothing Then

Works Fine
 
Upvote 0
I tried myself to add a second cell

Code:
If Not Intersect(Target, Range("E17:E17,J1:J1")) Is Nothing Then

Works Fine
:)

Or just
Code:
If Not Intersect(Target, Range("E17, J1")) Is Nothing Then
 
Last edited:
Upvote 0

Forum statistics

Threads
1,223,902
Messages
6,175,278
Members
452,629
Latest member
SahilPolekar

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top