PC Review


Reply
Thread Tools Rate Thread

Code to make only certain sheets visible

 
 
Michael
Guest
Posts: n/a
 
      11th Apr 2007
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


 
Reply With Quote
 
 
 
 
Dave Peterson
Guest
Posts: n/a
 
      11th Apr 2007
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 With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
How do I make Excel 2007 chart sheets visible C. Varnavas Microsoft Excel Charting 1 25th Apr 2010 03:19 PM
Sheets visible toggle code Ambassador Microsoft Excel Programming 3 24th Dec 2009 05:14 PM
Code to make only certain sheets visible Michael Microsoft Excel Discussion 7 12th Apr 2007 10:16 PM
Make upper left of sheets visible AD108 Microsoft Excel Programming 3 31st Jul 2006 10:22 AM
Code to make sheets in a workbook visible Jonsson Microsoft Excel Programming 5 30th Jan 2004 12:38 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 01:13 AM.