Solved

Hidden sheet tabs, unhide them

Posted on 2014-09-05
8
144 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 50

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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Convert between Excel file formats (.XLS, .XLSX, .XLSM) with/without macro option David Miller (dlmille) Intro Over this past Fall, I've had the opportunity to see several similar requests and have developed a couple related solutions associate…
How to quickly and accurately populate Word documents with Excel data, charts and images (including Automated Bookmark generation) David Miller (dlmille) Synopsis In this article you’ll learn how to use ExcelToWord! to copy data,charts, shapes …
The viewer will learn how to use a discrete random variable to simulate the return on an investment over a period of years, create a Monte Carlo simulation using the discrete random variable, and create a graph to represent the possible returns over…
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.

756 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