Thread: Hiding sheets
View Single Post
  #8   Report Post  
Posted to microsoft.public.excel.programming
Dave Peterson[_5_] Dave Peterson[_5_] is offline
external usenet poster
 
Posts: 1,758
Default Hiding sheets

And one more...

Option Explicit
Sub auto_open()

Dim iCtr As Long
Dim CurMonthName As String

CurMonthName = Format(Date, "mmm")

On Error Resume Next 'just in case of naming problems
'show the current month
Worksheets(CurMonthName).Visible = True
For iCtr = 1 To Worksheets.Count
If LCase(Worksheets(iCtr).Name) = LCase(CurMonthName) Then
'do nothing--it's already shown
Else
Worksheets(iCtr).Visible = False
End If
Next iCtr
On Error GoTo 0

End Sub

I think you'll find it's better to show the one worksheet first. Then hide all
the others.

If you get unlucky, you maybe hiding a worksheet that was the only visible
sheet.

If that happens, then your code will break, since there always has to be at
least one visible sheet in your workbook.

Are you any relation to JudithJubilee? She asked a similar question recently.

Natalie wrote:

Hello All,

I have numerous sheets and I would like to show or hide
them based on the month. IE. If it is Jan hide all my
other sheets apart from the Jan sheet, this is to stop
people seeing the data.

I got the following code from an MVP from this site. But
I don't know what to do with it. I'm a beginner in Vb so
please bear with me!!

Dim MyMonth As Integer
MyMonth = Month(Now())

Select Case MyMonth

Case 1 'If month number is 1 (Jan)
Sheets("Feb").Visible = False
Sheets("Mar").Visible = False
Case 2 'If Month number is 2 (Feb)
Sheets("Jan").Visible = False
Sheets("March").Visible = False
Case 3 'If Month number is 3 (Mar)
Sheets("Jan").Visible = False
Sheets("Mar").Visible = True
Sheets("Feb").Visible = False
End Select
End Sub

The Expert suggested I put this in the Open workbook
event??? Where is that please?

Thank for reading

Natalie


--

Dave Peterson