Solved

Hidden sheet tabs, unhide them

Posted on 2014-09-05
8
148 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 52

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 48

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
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 48

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 48

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 48

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

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

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

Excel can be a tricky bit of software to get your head around. Whilst you’ll be able to eventually get to grips with the basic understanding of how to get by, there are a few Excel tips that not everybody will even know about let alone know how to d…
Do you use a spreadsheet like Microsoft's Excel?  Have you ever wanted to link out to a non excel file on your computer or network drive?  This is the way I found to do it!
This Micro Tutorial demonstrates how to create Excel charts: column, area, line, bar, and scatter charts. Formatting tips are provided as well.
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.

630 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