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
 
Do you have a Sheet named exactly "Sheet6"?
Is it visible?
Is it protected?
the vba code name is Sheet6. it is visible and while it will be protected when this is resolved, it is not yet protected

1654704066679.png
 
Upvote 0

Excel Facts

Excel Wisdom
Using a mouse in Excel is the work equivalent of wearing a lanyard when you first get to college
You are trying to refer to the sheet by name in your code, not by index. It looks like it is not named "Sheet6", but rather "Order Appendix - Parcel Only".

So you either need to refer to it like:
VBA Code:
Worksheets("Order  Appendix - Parcel Only").Range("A32,A37").EntireRow.Hidden = True
or like:
VBA Code:
Sheet6.Range("A32,A37").EntireRow.Hidden = True

And the same is true for the rest of the sheets in your code.
 
Upvote 0
Solution
You are trying to refer to the sheet by name in your code, not by index. It looks like it is not named "Sheet6", but rather "Order Appendix - Parcel Only".

So you either need to refer to it like:
VBA Code:
Worksheets("Order  Appendix - Parcel Only").Range("A32,A37").EntireRow.Hidden = True
or like:
VBA Code:
Sheet6.Range("A32,A37").EntireRow.Hidden = True

And the same is true for the rest of the sheets in your code.
Oh my gosh, feeling silly on that one. It fixed the issue. Thank you so very much!
 
Upvote 0
You are welcome!
Glad I was able to help.
 
Upvote 0

Forum statistics

Threads
1,214,814
Messages
6,121,711
Members
449,049
Latest member
THMarana

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