Amend VBA code to refer to another sheet
Results 1 to 4 of 4

Thread: Amend VBA code to refer to another sheet
Thanks Thanks: 0 Likes Likes: 0

  1. #1
    Board Regular
    Join Date
    Jul 2018
    Location
    Auckland
    Posts
    257
    Post Thanks / Like
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    Default Amend VBA code to refer to another sheet

    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

  2. #2
    Board Regular
    Join Date
    May 2008
    Location
    Austria
    Posts
    1,080
    Post Thanks / Like
    Mentioned
    5 Post(s)
    Tagged
    0 Thread(s)

    Default Re: Amend VBA code to refer to another sheet

    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
    Silentwolf



    I use MS Office 2010 and Windows 7

  3. #3
    Board Regular
    Join Date
    Jul 2018
    Location
    Auckland
    Posts
    257
    Post Thanks / Like
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    Default Re: Amend VBA code to refer to another sheet

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

  4. #4
    Board Regular
    Join Date
    Jul 2018
    Location
    Auckland
    Posts
    257
    Post Thanks / Like
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    Default Re: Amend VBA code to refer to another sheet

    Don't worry. I've worked this out now

Some videos you may like

User Tag List

Tags for this Thread

Like this thread? Share it with others

Like this thread? Share it with others

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •