Solved

Hidden sheet tabs, unhide them

Posted on 2014-09-05
8
146 Views
Last Modified: 2014-09-08
I use the follow code on workbooks that have a ton of sheet tabs, it even show the hidden sheet tabs which is good.  However when a hidden sheet is selected to goto, it fails.  Is there a way to edit this so if a hidden tab is selected, it unhides it?


Private Sub cmdGoTo_Click()
    If cboSheets.ListIndex <> -1 Then
        Application.Goto Worksheets(cboSheets.Value).Range("A1")
        Unload Me
    End If
End Sub

Private Sub UserForm_Initialize()
Dim I As Long

    For I = 1 To Worksheets.Count
        cboSheets.AddItem Worksheets(I).Name
    Next I
End Sub

Open in new window

0
Comment
Question by:RWayneH
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
8 Comments
 
LVL 51

Accepted Solution

by:
Rgonzo1971 earned 250 total points
ID: 40305745
Hi,

pls try

Private Sub cmdGoTo_Click()
    If cboSheets.ListIndex <> -1 Then
        Worksheets(cboSheets.Value).Visible = xlSheetVisible
        Application.Goto Worksheets(cboSheets.Value).Range("A1")
        Unload Me
    End If
End Sub

Private Sub UserForm_Initialize()
Dim I As Long

    For I = 1 To Worksheets.Count
        cboSheets.AddItem Worksheets(I).Name
    Next I
End Sub


Regards
0
 
LVL 47

Assisted Solution

by:Martin Liss
Martin Liss earned 250 total points
ID: 40306087
If you want to retain the hidden/visible state after you are done, you can do this.

Private Sub cmdGoTo_Click()
Dim bHiddenState As Boolean

    If cboSheets.ListIndex <> -1 Then
        bHiddenState =  Worksheets(cboSheets.Value).Visible
        Worksheets(cboSheets.Value).Visible = xlSheetVisible
        Application.Goto Worksheets(cboSheets.Value).Range("A1")
        Worksheets(cboSheets.Value).Visible = bHiddenState
        Unload Me
    End If
End Sub

Private Sub UserForm_Initialize()
Dim I As Long

    For I = 1 To Worksheets.Count
        cboSheets.AddItem Worksheets(I).Name
    Next I
End Sub

Open in new window

0
 

Author Comment

by:RWayneH
ID: 40308874
retain the hidden status?  help me understand that.  When I change to a different sheet it re-hides it?  That may be useful but can you explain more of what that does?
0
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

 
LVL 47

Expert Comment

by:Martin Liss
ID: 40308969
What I'm assuming is that in your workbook that some sheets are hidden and that some are not, and after this process you want the hidden ones to remain hidden. If you were to use Rgonzo1971's code as is and a hidden sheet were selected from the combobox, that sheet would become visible until manually made hidden again.  What my additional couple of lines of code does is to "remember" whether the sheet was visible or not, and if it's hidden, restore it to hidden after the process is done.
0
 

Author Comment

by:RWayneH
ID: 40310418
Thanks for the explanation.  What if the process is manual?  Could it flip back to hidden, when a different sheet tab get the focus?
0
 
LVL 47

Expert Comment

by:Martin Liss
ID: 40310452
It only affects the sheet that is selected via the combobox, and the only thing it does is that after line 6 in the code in Post ID ID: 40306087 makes the sheet visible if it was hidden, line 8 would make it hidden again. (If it were visible to begin with it would stay visible.)
0
 

Author Closing Comment

by:RWayneH
ID: 40310782
Both EXCELlent solutions thanks.
0
 
LVL 47

Expert Comment

by:Martin Liss
ID: 40310810
Both EXCELlent solutions thanks.
lol

You're welcome and I'm glad I was able to help.

In my profile you'll find links to some articles I've written that may interest you.
Marty - MVP 2009 to 2014
0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Copy Picture from one workbook to newly created workbook 12 39
Vlookup Help 3 29
Cell Manipulation 37 53
VBA Lookup Problem 2 13
Some code to ensure data integrity when using macros within Excel. Also included code that helps secure your data within an Excel workbook.
When you see single cell contains number and text, and you have to get any date out of it seems like cracking our heads.
This Micro Tutorial will demonstrate in Microsoft Excel how to add style and sexy appeal to horizontal bar charts.
This Micro Tutorial will demonstrate the scrolling table in Microsoft Excel using the INDEX function.

738 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question