View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Dave Peterson Dave Peterson is offline
external usenet poster
 
Posts: 35,218
Default Code to make only certain sheets visible

You have replies at your other post.

Michael wrote:

Hello everyone,

I have a workbook with 3 worksheets (Sheet1, Sheet2, Sheet3) and 2
pivotcharts (Chart1, Chart2). I want to write a sub that when it is called
it cycles through all of the worksheets and charts (all of the workbook
objects) and toogle sheet visibility. I want to have only one of the
following objects visible every time my code runs:

- Sheet1
- Sheet2
- Chart1
- Chart2

My sample code is the one below but its not even close. Can I get some help?

Sub ToogleSheetVisiblity()
'You must leave at least one Sheet visible
Dim wsSheet As Worksheet
On Error Resume Next 'If code tries to hide all Sheets
For Each wsSheet In Worksheets
If wsSheet.Name = "Sheet1"
Worksshets(wsSheet.Index - 1).Visible = False
wsSheet.Visible = True
End If
Next wsSheet
On Error GoTo 0 'One sheet will always be left visible
End Sub

Thanks
Michael


--

Dave Peterson