Solved

Hidden sheet tabs, unhide them

Posted on 2014-09-05
8
139 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 48

Accepted Solution

by:
Rgonzo1971 earned 250 total points
Comment Utility
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 45

Assisted Solution

by:Martin Liss
Martin Liss earned 250 total points
Comment Utility
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
Comment Utility
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
 
LVL 45

Expert Comment

by:Martin Liss
Comment Utility
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
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 

Author Comment

by:RWayneH
Comment Utility
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 45

Expert Comment

by:Martin Liss
Comment Utility
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
Comment Utility
Both EXCELlent solutions thanks.
0
 
LVL 45

Expert Comment

by:Martin Liss
Comment Utility
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

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Introduction This Article briefly covers methods of calculating the NPV and IRR variants in Excel as well as the limitations in calculating and interpreting IRR results. Paraphrasing Richard Shockley, author of my favourite finance reference tex…
Improved? Move/Copy Add-in Replacement - How to avoid the annoying, “A formula or sheet you want to move or copy contains the name XXX, which already exists on the destination worksheet.” David Miller (dlmille)  It was one of those days… I wa…
The view will learn how to download and install SIMTOOLS and FORMLIST into Excel, how to use SIMTOOLS to generate a Monte Carlo simulation of 30 sales calls, and how to calculate the conditional probability based on the results of the Monte Carlo …
This Micro Tutorial demonstrates in Microsoft Excel how to consolidate your marketing data by creating an interactive charts using form controls. This creates cool drop-downs for viewers of your chart to choose from.

744 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now