Hoping for help - vba on worksheet 2 events

srsanddrs

New Member
Joined
Jun 8, 2022
Messages
7
Office Version
  1. 365
Platform
  1. Windows
Hello,

Would greatly appreciate some help on this issue. I have a multi worksheet book for quoting. There are a number of conditional elements that with some trial and error are all working except one thing. I have two change type events that need to trigger on the same worksheet, one changes elements within the worksheet and the other is meant to hide rows on other worksheets based on a condition in this worksheet. After learning I could not have two same event types on the same worksheet, i have tried combining based on what I could research. The code is just below. The part that is listed as the second block works fine. the top part does not. it gives no error message that i can see but nor am I able to step through the code in the vba module. Originally I had tried saying <> "Netsuite" and having the hide True come first but as that wasn't doing anything, tried this other way but same result. I had also originally tried using Row instead of Range but since not contiguous thought needed to be range.

VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)

    If Target.Address = "$H$3" Then
        If Target.Value = "Netsuite" Then
            Worksheets("Sheet6").Range("A32,A37").EntireRow.Hidden = False
            Worksheets("Sheet7").Range("A35,A40,A44").EntireRow.Hidden = False
            Worksheets("Sheet8").Range("A38,A45,A48").EntireRow.Hidden = False
            Worksheets("Sheet9").Range("A44,A50,A53,A54").EntireRow.Hidden = False
            Worksheets("Sheet10").Range("A7,A52:54").EntireRow.Hidden = False
        Else
            Worksheets("Sheet6").Range("A32,A37").EntireRow.Hidden = True
            Worksheets("Sheet7").Range("A35,A40,A44").EntireRow.Hidden = True
            Worksheets("Sheet8").Range("A38,A45,A48").EntireRow.Hidden = True
            Worksheets("Sheet9").Range("A44,A50,A53,A54").EntireRow.Hidden = True
            Worksheets("Sheet10").Range("A7,A52:54").EntireRow.Hidden = True
        End If
    End If
    
' *** Next block*** [this part below seems to work just fine]
    
    If Target.Address = "$B$11" Then
        Range("b13:b22,b25:b31,B34:b38,j25:j31,j34:j38,k11,k13:k22,k25:k31,k34:k38").Value = ""
    End If
    
End Sub
 

Excel Facts

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.
Welcome to the Board!

How exactly are you trying to trigger the first block?
If it is currently in the Sheet module, the first block of code will only run as cell H3 is being changed to "Netsuite".
Is that how you want it to work?
 
Upvote 0
Welcome to the Board!

How exactly are you trying to trigger the first block?
If it is currently in the Sheet module, the first block of code will only run as cell H3 is being changed to "Netsuite".
Is that how you want it to work?
Hi Thanks for reaching out.

I was trying to get it to hide the rows on the other sheets when H3's dropdown selection is anything other than Netsuite (or blank would be good to). When Netsuite is selected no rows in those other sheets should be hidden
 
Upvote 0
Hi Thanks for reaching out.

I was trying to get it to hide the rows on the other sheets when H3's dropdown selection is anything other than Netsuite (or blank would be good to). When Netsuite is selected no rows in those other sheets should be hidden
Right, but understand that the Worksheet_Change event procedure code only runs when the specific cell is changed.
So the way you have the code written, it will only run when cell H3 is physically changed.
 
Upvote 0
Also note that you have a few typos in your code.
These lines:
Rich (BB code):
 Worksheets("Sheet10").Range("A7,A52:54")
should look like this:
Rich (BB code):
 Worksheets("Sheet10").Range("A7,A52:A54")
 
Upvote 0
Right, but understand that the Worksheet_Change event procedure code only runs when the specific cell is changed.
So the way you have the code written, it will only run when cell H3 is physically changed.
Correct when that is changed, which happens anytime we quote it should hide, unhide the rows in those other sheets. It does not. Thanks for the typo catch! I fixed my typo and now i get this error when i change the value

1654702505770.png
 
Upvote 0
Correct when that is changed, which happens anytime we quote it should hide, unhide the rows in those other sheets. It does not. Thanks for the typo catch! I fixed my typo and now i get this error when i change the value

View attachment 66597
If you hit debug, which line of code does it highlight?
And what value exactly are you entering in to what cell that causes this error?
 
Upvote 0
If you hit debug, which line of code does it highlight?
And what value exactly are you entering in to what cell that causes this error?
1654703040728.png


I entered IFS (another ERP) from the drop down so the expectation was rows would hide in those other sheets
 
Upvote 0
Do you have a Sheet named exactly "Sheet6"?
Is it visible?
Is it protected?
 
Upvote 0

Forum statistics

Threads
1,214,979
Messages
6,122,557
Members
449,088
Latest member
davidcom

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