View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.misc
Dave Peterson Dave Peterson is offline
external usenet poster
 
Posts: 35,218
Default macro to hide sheets

Sometimes, If/then statements can get unruly with lots of criteria.

Private Sub CommandButton2_Click()
dim i as long
For i = 1 To Worksheets.Count
select case lcase(worksheets(i).codename)
case is = "sheet1","sheet5","sheet9" 'all lower case!
'do nothing
case else
sheets(i).visible = xlsheethidden
end select
next i
Sheet1.Select
End Sub

EricBB wrote:

why the below is not working? pls. help...

Private Sub CommandButton2_Click()
For i = 1 To Worksheets.Count
If Not (Worksheets(i).CodeName = "Sheet1" Or "Sheet5" Or "Sheet9") Then
Sheets(i).Visible = False
Next
Sheet1.Select
End Sub


--

Dave Peterson