Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 249
Default Hiding sheets using code

i have a spreadsheet with sheets named as follows

St1, St2, St3, St4, St5 etc...

I would like to enter a number into a cell on a separate sheet that will
result in
only showing the sheets up to that number and hide the rest.

For example if i enter 3, I would like St1, St2 and St3 to show and St4, St5
etc
to be hidden.

Can anyone help?

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10,593
Default Hiding sheets using code


For i = 1 to Range("B2").value
Worksheets("St" & i).Visible = xlSheetHidden
Next i

--
---
HTH

Bob


(there's no email, no snail mail, but somewhere should be gmail in my addy)



"Roger on Excel" wrote in message
...
i have a spreadsheet with sheets named as follows

St1, St2, St3, St4, St5 etc...

I would like to enter a number into a cell on a separate sheet that will
result in
only showing the sheets up to that number and hide the rest.

For example if i enter 3, I would like St1, St2 and St3 to show and St4,
St5
etc
to be hidden.

Can anyone help?



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,501
Default Hiding sheets using code

Roger,

Right click your 'other' shhet tabe (Menu in my case) view code and oaste
this in

Private Sub Worksheet_Change(ByVal Target As Range)
Dim ws As Worksheet
If Target.Cells.Count 1 Or IsEmpty(Target) Then Exit Sub
If Target.Address = "$A$1" Then
If IsNumeric(Target) Then
On Error Resume Next
Application.EnableEvents = False
For i = 1 To worksheets.Count
If worksheets(i).Name < "Menu" And Val(Right(worksheets(i).Name,
1)) Target.Value Then
worksheets(i).Visible = False
Else
worksheets(i).Visible = True
End If
Next
Application.EnableEvents = True
On Error GoTo 0
End If
End If
End Sub

Enter a number in A1 of that sheet and sheets will become hidden or visible

Mike

"Roger on Excel" wrote:

i have a spreadsheet with sheets named as follows

St1, St2, St3, St4, St5 etc...

I would like to enter a number into a cell on a separate sheet that will
result in
only showing the sheets up to that number and hide the rest.

For example if i enter 3, I would like St1, St2 and St3 to show and St4, St5
etc
to be hidden.

Can anyone help?

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 249
Default Hiding sheets using code

Excellent - Thanks very much - perfect !!!


All the best,

Roger

"Mike H" wrote:

Roger,

Right click your 'other' shhet tabe (Menu in my case) view code and oaste
this in

Private Sub Worksheet_Change(ByVal Target As Range)
Dim ws As Worksheet
If Target.Cells.Count 1 Or IsEmpty(Target) Then Exit Sub
If Target.Address = "$A$1" Then
If IsNumeric(Target) Then
On Error Resume Next
Application.EnableEvents = False
For i = 1 To worksheets.Count
If worksheets(i).Name < "Menu" And Val(Right(worksheets(i).Name,
1)) Target.Value Then
worksheets(i).Visible = False
Else
worksheets(i).Visible = True
End If
Next
Application.EnableEvents = True
On Error GoTo 0
End If
End If
End Sub

Enter a number in A1 of that sheet and sheets will become hidden or visible

Mike

"Roger on Excel" wrote:

i have a spreadsheet with sheets named as follows

St1, St2, St3, St4, St5 etc...

I would like to enter a number into a cell on a separate sheet that will
result in
only showing the sheets up to that number and hide the rest.

For example if i enter 3, I would like St1, St2 and St3 to show and St4, St5
etc
to be hidden.

Can anyone help?

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 249
Default Hiding sheets using code

By the way I have sheets named St10, St11, St12, yet these do not disappear -
is there a modification to the code to take account of these sheets also?

"Mike H" wrote:

Roger,

Right click your 'other' shhet tabe (Menu in my case) view code and oaste
this in

Private Sub Worksheet_Change(ByVal Target As Range)
Dim ws As Worksheet
If Target.Cells.Count 1 Or IsEmpty(Target) Then Exit Sub
If Target.Address = "$A$1" Then
If IsNumeric(Target) Then
On Error Resume Next
Application.EnableEvents = False
For i = 1 To worksheets.Count
If worksheets(i).Name < "Menu" And Val(Right(worksheets(i).Name,
1)) Target.Value Then
worksheets(i).Visible = False
Else
worksheets(i).Visible = True
End If
Next
Application.EnableEvents = True
On Error GoTo 0
End If
End If
End Sub

Enter a number in A1 of that sheet and sheets will become hidden or visible

Mike

"Roger on Excel" wrote:

i have a spreadsheet with sheets named as follows

St1, St2, St3, St4, St5 etc...

I would like to enter a number into a cell on a separate sheet that will
result in
only showing the sheets up to that number and hide the rest.

For example if i enter 3, I would like St1, St2 and St3 to show and St4, St5
etc
to be hidden.

Can anyone help?

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
hiding sheets dstiefe Excel Worksheet Functions 1 October 7th 09 11:42 PM
need code for hiding/unhiding sheets using checkboxes pzx8hf Excel Worksheet Functions 1 August 13th 08 12:11 AM
hiding zero values on all sheets & by default on new sheets WiFiMike2006 Excel Worksheet Functions 4 January 19th 07 08:13 PM
Locking Sheets / Hiding Sheets Lee Harris Excel Worksheet Functions 4 November 29th 05 07:21 AM
Hiding Sheets Eric[_14_] Excel Programming 4 November 26th 03 06:38 PM


All times are GMT +1. The time now is 08:23 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"