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