Amend VBA code to refer to another sheet

tlc53

Active Member
Joined
Jul 26, 2018
Messages
399
Hi,

I have the below code which works fine if the target "No._Partners" is on the same sheet. However, in this case, "No._Partners" is based on another sheet. Can someone please help me change the first part of the code to refer to another sheet? I'm not quite sure how to do that..

Thanks!

Code:
Private Sub Worksheet_Change(ByVal Target As Range)


If Not Intersect(Target, Range("No._Partners")) Is Nothing Then


If Target.Cells.CountLarge > 1 Then Exit Sub
Select Case Target.Value


    Case "Please Select"
        Range("159:167").EntireRow.Hidden = True
    Case 2
        Range("159:167").EntireRow.Hidden = False
        Range("160:167").EntireRow.Hidden = True
    Case 3
        Range("159:167").EntireRow.Hidden = False
        Range("161:167").EntireRow.Hidden = True
    Case 4
        Range("159:167").EntireRow.Hidden = False
        Range("162:167").EntireRow.Hidden = True
    Case 5
        Range("159:167").EntireRow.Hidden = False
        Range("163:167").EntireRow.Hidden = True
    Case 6
        Range("159:167").EntireRow.Hidden = False
        Range("164:167").EntireRow.Hidden = True
    Case 7
        Range("159:167").EntireRow.Hidden = False
        Range("165:167").EntireRow.Hidden = True
    Case 8
        Range("159:167").EntireRow.Hidden = False
        Range("166:167").EntireRow.Hidden = True
    Case 9
        Range("159:167").EntireRow.Hidden = False
        Range("167:167").EntireRow.Hidden = True
    Case 10
        Range("159:167").EntireRow.Hidden = False
     
   End Select
End If
End Sub
 

Excel Facts

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.
Hello,
I am not sure if I understand you correctly.. but if you like to refer to another worksheet within the workbook you need a different event not the change event of the worksheet.
Create a sub instead of using the ChangeEvent of the worksheet and then you refer to another worksheet in that code.

HTH
 
Upvote 0
Thank you. However, I'm not sure how I create a sub instead of using the ChangeEvent. Any chance you could elaborate please?
 
Upvote 0

Forum statistics

Threads
1,213,530
Messages
6,114,162
Members
448,554
Latest member
Gleisner2

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