Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 31
Default 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   Report Post  
Posted to microsoft.public.excel.programming
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
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
How do I make Excel 2007 chart sheets visible C. Varnavas Charts and Charting in Excel 1 April 25th 10 03:19 PM
Slow code when used as VBA code instead of macro (copying visible columns) [email protected] Excel Programming 3 April 2nd 07 05:26 PM
Make upper left of sheets visible AD108 Excel Programming 3 July 31st 06 10:22 AM
Code to make sheets in a workbook visible Jonsson[_4_] Excel Programming 5 January 30th 04 12:38 PM
unprotect sheet in code and make sheet visible peach255 Excel Programming 1 August 1st 03 03:28 AM


All times are GMT +1. The time now is 03:15 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"