VBA - hide all but one sheet including charts

LORDMARKS

New Member
Joined
Jun 5, 2014
Messages
39
Hi all (office 97)

I have used this site for years, but this is my first post, as I can't get any of the older posts to work.


I have a workbook over about 15 sheets including charts.

When you open it up you can only see the "INTERFACE" sheet and use buttons to select all other sheets / reports / charts.

I have been manually selecting each sheet and unhiding, then the "HOME" button selects each sheet and hides it again.

What I am trying to do is clean up my CODE and reduce the fat, so I have been looking for a bit of code that would select each sheet in turn and unhide it (and in reverse)


The best i have managed so far sort of worked but keeps failing on the charts. It would also be good if the home button passworded each sheet as well.


Thanks in advance
 

Excel Facts

Waterfall charts in Excel?
Office 365 customers have access to Waterfall charts since late 2016. They were added to Excel 2019.
A Quick for Loop

To unhide
Code:
Dim WS as Worksheet

For each WS in Thisworkbook.worksheets
  If WS.name <> "Whatever sheet you don't want hidden" then
      WS.Visible = xlSheetVisible
      WS.Unprotect "Password"
  End if
Next WS

To Hide
Code:
For each WS in Thisworkbook.worksheets
  If WS.name <> "Whatever sheet you don't want hidden" then
      WS.Visible = xlSheetHidden
      WS.Protect "Password"
  End if
Next WS
 
Upvote 0
Can you post the code you already have and we'll help you modify it.
 
Upvote 0
Code:
Sub hideEm()
    
    For x = 1 To ActiveWorkbook.Worksheets.Count
        If LCase(ActiveWorkbook.Worksheets(x).Name) <> LCase("interface") Then
            ActiveWorkbook.Worksheets(x).Visible = xlHidden
        End If
    Next x
    
    For Z = 1 To ActiveWorkbook.Charts.Count
            ActiveWorkbook.Charts(Z).Visible = xlHidden
    Next Z
End Sub
Sub showEm()
    For x = 1 To ActiveWorkbook.Worksheets.Count
        If LCase(ActiveWorkbook.Worksheets(x).Name) <> LCase("interface") Then
            ActiveWorkbook.Worksheets(x).Visible = True
        End If
    Next x
    
    For Z = 1 To ActiveWorkbook.Charts.Count
            ActiveWorkbook.Charts(Z).Visible = True
    Next Z
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,108
Messages
6,170,140
Members
452,304
Latest member
Thelingly95

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