Unhide all sheets that do not contain certain words in sheet name

WisdomandLaughter

New Member
Joined
May 28, 2008
Messages
35
This may be a fairly simple matter for someone well versed in VBA code, however it would take me days to figure out.
<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:eek:ffice:eek:ffice" /><o:p> </o:p>
I pulled some code off the internet to “force” users to enable macros by hiding all sheets except a “Welcome Page”. It works great except that it also unhides sheets that are meant to be hidden by when the workbook is opened.
<o:p> </o:p>
How would I adjust the following code so any sheets/ tabs containing the words “New Project” are not automatically unhidden? Below is the code pertaining to unhiding. I did not paste the code in its entirety as it is fairly long.
<o:p> </o:p>
Option Explicit<o:p></o:p>
<o:p></o:p>
Const WelcomePage = "Macros"
<HR align=center width="100%" SIZE=2>​
<o:p> </o:p>
Private Sub ShowAllSheets()<o:p></o:p>
Dim ws As Worksheet<o:p></o:p>
<o:p></o:p>
For Each ws In ThisWorkbook.Worksheets<o:p></o:p>
If Not ws.Name = WelcomePage Then ws.Visible = xlSheetVisible<o:p></o:p>
Next ws<o:p></o:p>
<o:p></o:p>
Worksheets(WelcomePage).Visible = xlSheetVeryHidden<o:p></o:p>
End Sub<o:p></o:p>
<o:p> </o:p>
<o:p> </o:p>
Thank you for your help!!!
<o:p> </o:p>
Judy
 

Excel Facts

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying
Try

Code:
Const WelcomePage = "Macros"

Sub ShowAllSheets()
Dim ws As Worksheet

For Each ws In ThisWorkbook.Worksheets
    If Not ws.Name = WelcomePage Then
        If Not ws.Name Like "*New Project*" Then ws.Visible = xlSheetVisible
    End If
Next ws

Worksheets(WelcomePage).Visible = xlSheetVeryHidden
End Sub
 
Upvote 0
Thank you. That works great. Except I have the following code assigned to a button (shape really) that no longer works (the code appears to be making my "New Project" tabs very hidden):

Sub GotoNextHiddenWS()

mySh = Worksheets(Sheet2.Name).Index
'Loop though worksheets and check if hidden
Do While mySh < Worksheets.Count
If Sheets(mySh + 1).Visible = 0 Then
Sheets(mySh + 1).Visible = -1
Sheets(mySh + 1).Select
Exit Sub
Else
mySh = mySh + 1
End If
Loop
End Sub
 
Upvote 0
Okay I have edited the GotoNextHiddenWS to unhide the very hidden sheets and it is functioning again.

However the sheet named "Macros" should remain very hidden throughout this loop. Would you be able to suggest how I can achieve that?

Thank you again for all your help.
Judy
 
Upvote 0
My apologies.

Sub GotoNextHiddenWS()
mySh = Worksheets(Sheet2.Name).Index

Do While mySh < Worksheets.Count
If Sheets(mySh + 1).Visible = 2 Then
Sheets(mySh + 1).Visible = -1
Sheets(mySh + 1).Select
Exit Sub
Else
mySh = mySh + 1
End If
Loop
End Sub



As it loops I would like the worksheet named "Macros" to remain very hidden.

 
Upvote 0
Try

Code:
Sub GotoNextHiddenWS()
mySh = Worksheets(Sheet2.Name).Index
Do While mySh < Worksheets.Count
    If Sheets(mySh + 1).Name <> "Macros" Then
        If Sheets(mySh + 1).Visible = 2 Then
            Sheets(mySh + 1).Visible = -1
            Sheets(mySh + 1).Select
            Exit Sub
        Else
            mySh = mySh + 1
        End If
    End If
Loop
End Sub
 
Upvote 0
That appears to cause an endless loop. I'm not sure.

The first click works and the first hidden sheet not macros unhides. The second click of the button (shape really) causes the hour glass that doesn't go away and the Program Not responding box to appear if I close the file.
 
Upvote 0

Forum statistics

Threads
1,214,583
Messages
6,120,383
Members
448,956
Latest member
JPav

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top