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
You're missing an EndIf (or an underscore after Then to create a line
break) and you can't do a comparison like that.
Also, I'm assuming that you want sheets 1m 5 and 9 NOT hidden given
that you try to select sheet1 at the end, which you can't do if it's
hidden.
One way of doing it, as close to your original one as possible:
Private Sub CommandButton2_Click()
Dim i As Integer
Dim s As String
For i = 1 To Worksheets.Count
s = Worksheets(i).CodeName
If (s <> "Sheet1" And _
s <> "Sheet5" And s <> "Sheet9") Then _
ThisWorkbook.Worksheets(i).Visible = xlSheetHidden
Else
ThisWorkbook.Worksheets(i).Visible = xlSheetVisible
End If
Next
Sheet1.Select
End Sub