Hiding/Unhiding Graph Sheets
Posted by Stan on October 22, 2001 9:27 AM
Mark O'Brien had provided me with the following code on this message board to hide all but one worksheet. I've adapted it to my needs and it has worked like a charm.
But I just ran into a "snag". I want to hide all but a chart sheet. In the SheetVisible sub, it cycles through all of the sheets and sets my sheet graph to visible and hides all others. But as soon as it reaches the last sheet name I get an error - "Method 'Visible' of Object '_Chart' failed." I would expect this if it had tried to close all sheets (at least one sheet should be open) but it did set my chart sheet (26th of 30 sheets) to visible at the line:
If Sheets(i).Name = sht Then
Sheets(i).Visible = True
Any ideas to get me pointed in the right direction?
Stan
Public Sub SheetGuide()
' Declare Variable
Dim sht As String
' Initialise Variable
sht = "Sheet3"
' Call Routine that makes sheet visible
SheetVisible sht
End Sub
Private Sub SheetVisible(ByVal sht As String)
Dim shtVisible As String
Application.ScreenUpdating = False
For i = 1 To Sheets.count
' Excel always needs to have at least 1 sheet visible
If Sheets(i).Name = Sheets.Item(1).Name Then
If Sheets(i).Name <> sht Then
Sheets.Item(1).Visible = True
i = i + 1
End If
End If
If Sheets(i).Name = sht Then
Sheets(i).Visible = True
Else
Sheets(i).Visible = False
End If
Next i
If Sheets.Item(1).Name <> sht Then
Sheets.Item(1).Visible = False
End If
End Sub