Amend VBA code to refer to another sheet

tlc53

Active Member
Joined
Jul 26, 2018
Messages
365
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
 

Some videos you may like

Excel Facts

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.

silentwolf

Well-known Member
Joined
May 14, 2008
Messages
1,123
Office Version
2016
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
 

tlc53

Active Member
Joined
Jul 26, 2018
Messages
365
Thank you. However, I'm not sure how I create a sub instead of using the ChangeEvent. Any chance you could elaborate please?
 

Watch MrExcel Video

Forum statistics

Threads
1,102,508
Messages
5,487,291
Members
407,590
Latest member
Grobler

This Week's Hot Topics

Top