Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Hidden sheet tabs, unhide them

Posted on 2014-09-05
8
Medium Priority
?
152 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
  • 4
  • 3
8 Comments
 
LVL 53

Accepted Solution

by:
Rgonzo1971 earned 1000 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 49

Assisted Solution

by:Martin Liss
Martin Liss earned 1000 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 49

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 49

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 49

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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents.  The steps to find the Templates folder path are …
This article describes a serious pitfall that can happen when deleting shapes using VBA.
This Micro Tutorial will demonstrate the scrolling table in Microsoft Excel using the INDEX function.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

772 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