Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
Code to make only certain sheets visible
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 |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
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 |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
How do I make Excel 2007 chart sheets visible | Charts and Charting in Excel | |||
Slow code when used as VBA code instead of macro (copying visible columns) | Excel Programming | |||
Make upper left of sheets visible | Excel Programming | |||
Code to make sheets in a workbook visible | Excel Programming | |||
unprotect sheet in code and make sheet visible | Excel Programming |