+ Reply to Thread
Results 1 to 6 of 6

Thread: Hiding Worksheet on Value

  1. #1
    Registered User
    Join Date
    11-09-2008
    Location
    Michigan
    Posts
    3

    Hiding Worksheet on Value

    Greetings to all,

    So this is my first time doing coding in excel and I've searched the forums and scrapped this together.

    What I'm trying to do here is in H5, if it is set to Small then I want to hide sheets 8. 6509 Core1 - Med or Lg Site, 9. 6509 Core2 - Med or Lg Site and 10. Uplink Map - Med or Lg if it's set to anything else then hide the tabs 8. 3750 Core1 - Small Site, 9. 3750 Core2 - Small Site, and 10. Uplink Map - Small. I have this set on Sheet1 (1. Cover Sheet). Here's the code...

    Sub Number_Cores()
      If Range("H5").Value = "Small" Then
        Sheets("8. 6509 Core1 - Med or Lg Site").Visible = False
        Sheets("9. 6509 Core2 - Med or Lg Site").Visible = False
        Sheets("10. Uplink Map - Med or Lg").Visible = False
      Else
        Sheets("8. 3750 Core1 - Small Site").Visible = False
        Sheets("9. 3750 Core2 - Small Site").Visible = False
        Sheets("10. Uplink Map - Small").Visible = False
      End If
    End Sub
    So what is happening is it's getting all confused and mixing up. Hiding some but not hiding others. Also is there a way to reset the tabs so they are all visible?

    Thanks in advance...

  2. #2
    Forum Moderator Paul's Avatar
    Join Date
    02-05-2007
    Location
    Wisconsin
    MS-Off Ver
    2007
    Posts
    5,953
    Hi tearl,

    When referring to multiple sheets within one macro, I'd recommend always specifying the sheet you're referring to, e.g.
    Sub Number_Cores()
      If Sheets("1. Cover Sheet").Range("H5").Value = "Small" Then
        Sheets("8. 6509 Core1 - Med or Lg Site").Visible = False
        Sheets("9. 6509 Core2 - Med or Lg Site").Visible = False
        Sheets("10. Uplink Map - Med or Lg").Visible = False
      Else
        Sheets("8. 3750 Core1 - Small Site").Visible = False
        Sheets("9. 3750 Core2 - Small Site").Visible = False
        Sheets("10. Uplink Map - Small").Visible = False
      End If
    End Sub
    If that doesn't fix the problem, let us know..

  3. #3
    Forum Moderator Paul's Avatar
    Join Date
    02-05-2007
    Location
    Wisconsin
    MS-Off Ver
    2007
    Posts
    5,953
    To answer your second question (make all sheets visible again), you could use a macro such as:
    Sub showAll()
    Dim i as Long
    
    For i = 1 to Thisworkbook.Worksheets.Count
        Sheets(i).Visible = True
    Next i
    End Sub

  4. #4
    Registered User
    Join Date
    11-09-2008
    Location
    Michigan
    Posts
    3
    Nope, still no luck. I have changed the code to be 2 different IF statements and it didn't make any difference. Does it make a difference that H5 is a drop down box?

    Thanks,

    Tom

    Quote Originally Posted by pjoaquin View Post
    Hi tearl,

    When referring to multiple sheets within one macro, I'd recommend always specifying the sheet you're referring to, e.g.
    Sub Number_Cores()
      If Sheets("1. Cover Sheet").Range("H5").Value = "Small" Then
        Sheets("8. 6509 Core1 - Med or Lg Site").Visible = False
        Sheets("9. 6509 Core2 - Med or Lg Site").Visible = False
        Sheets("10. Uplink Map - Med or Lg").Visible = False
      Else
        Sheets("8. 3750 Core1 - Small Site").Visible = False
        Sheets("9. 3750 Core2 - Small Site").Visible = False
        Sheets("10. Uplink Map - Small").Visible = False
      End If
    End Sub
    If that doesn't fix the problem, let us know..

  5. #5
    Forum Moderator Paul's Avatar
    Join Date
    02-05-2007
    Location
    Wisconsin
    MS-Off Ver
    2007
    Posts
    5,953
    How about posting a copy of your workbook with any private data removed. All we really need to see is the sheets and cell H5 of the "1. Cover Sheet" (and if H5 is linked to a range, don't delete that range of course).

    First thing I'd check, though, is that your worksheet tabs are named EXACTLY the same as you have it in the macro.. same spelling, capitalization, spacing, punctuation. Any difference and it will not work.

  6. #6
    Registered User
    Join Date
    11-09-2008
    Location
    Michigan
    Posts
    3
    Hey Guys, Sorry this took so long... I had to quit looking at this as my eyes were starting to bleed...

    Here is a scrubbed copy of my doc. It's kind of massive so I zip'd it up.

    I'm trying to do a couple things here...

    1. Based on the value of H5, I'm trying to hide either tabs 8. 3750 Core1 - Small Site, 9. 3750 Core2 - Small Site and 10. Uplink Map - Small or 8. 6509 Core1 - Med or Lg Site, 9. 6509 Core2 - Med or Lg Site and 10. Uplink Map - Med or Lg.

    2. Based on the value of F5, I'm trying to hide columns J, O, P, Q, R and V in tab 7. Access IP Addrs - MNS. If its 2 then they are visible. If its 1 then they are EntireColumn.visable = False. Messing with this yesterday, I could get the auto-calculation to make them disappear, but not re-appear.

    Thanks for any help you can provide.
    Attached Files Attached Files

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.2.0