VBA Help - Combine 2 Worksheet_Change Events - Excel 2016

Johnny Thunder

Well-known Member
Joined
Apr 9, 2010
Messages
693
Office Version
  1. 2016
Platform
  1. MacOS
Hi group,

So I have two Worksheet_Change Events written out but I realized today that you can only have one per page so here is the code, can anyone suggest a revision to combine the two into one so that I can wrap up this project?

Code:
----------------------------------------------------------------------------------------------------------------------
'--- Hide Rows based on target value description
'----------------------------------------------------------------------------------------------------------------------
Private Sub Worksheet_Change(ByVal Target As Range)
 Dim Pass As String


 Pass = "password"


If Target.Address = "$C$9" Then


 ActiveSheet.Unprotect Pass


     If Target <> "Management" Then
        Range("34:37").EntireRow.Hidden = True
    Else
        Range("34:37").EntireRow.Hidden = False
    End If


End If


ActiveSheet.Protect Pass


End Sub


'----------------------------------------------------------------------------------------------------------------------
'--- Run specific code based on two cell value
'----------------------------------------------------------------------------------------------------------------------
Private Sub Worksheet_Change(ByVal Target As Range)
 
    If Target.Address = "$C$16" Then 'Need this line to also include the C16
    
            If Target <> vbNullString And Range("C11").Value = "Edit Entry" Then
            
                Call PopulateEntry
            
            ElseIf Target <> vbNullString And Range("C11").Value = "Deactivate" Then
            
                Call PopulateEntry
            
            End If
                        
    End If


End Sub
 

Excel Facts

Best way to learn Power Query?
Read M is for (Data) Monkey book by Ken Puls and Miguel Escobar. It is the complete guide to Power Query.
Hi group,

So I have two Worksheet_Change Events written out but I realized today that you can only have one per page so here is the code, can anyone suggest a revision to combine the two into one so that I can wrap up this project?

Rich (BB code):
----------------------------------------------------------------------------------------------------------------------
'--- Hide Rows based on target value description
'----------------------------------------------------------------------------------------------------------------------
Private Sub Worksheet_Change(ByVal Target As Range)
 Dim Pass As String


 Pass = "password"


If Target.Address = "$C$9" Then


 ActiveSheet.Unprotect Pass


     If Target <> "Management" Then
        Range("34:37").EntireRow.Hidden = True
    Else
        Range("34:37").EntireRow.Hidden = False
    End If


End If


ActiveSheet.Protect Pass


End Sub


'----------------------------------------------------------------------------------------------------------------------
'--- Run specific code based on two cell value
'----------------------------------------------------------------------------------------------------------------------
Private Sub Worksheet_Change(ByVal Target As Range)
 
    If Target.Address = "$C$16" Then 'Need this line to also include the C16
    
            If Target <> vbNullString And Range("C11").Value = "Edit Entry" Then
            
                Call PopulateEntry
            
            ElseIf Target <> vbNullString And Range("C11").Value = "Deactivate" Then
            
                Call PopulateEntry
            
            End If
                        
    End If


End Sub
Try just removing the red code
 
Last edited:
Upvote 0

Forum statistics

Threads
1,213,524
Messages
6,114,117
Members
448,549
Latest member
brianhfield

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