Hi,
I created the below code a few months ago but just wondering how I could make it shorter?
The premise of it is that you enter the admin password and it will hide 6 admin sheets using their codenames.
This is then assigned to a button in my workbook and it will hide and unhide.
Is there a way to assign the codenames to an array variable? This will make updating easier if I need to add a new sheet or delete.
Also, to decide on opening or closing, I pass it through an IF statement in the line below. Can I use an Array(Codenames).count to switch the 6?
Full code:
I created the below code a few months ago but just wondering how I could make it shorter?
The premise of it is that you enter the admin password and it will hide 6 admin sheets using their codenames.
This is then assigned to a button in my workbook and it will hide and unhide.
Is there a way to assign the codenames to an array variable? This will make updating easier if I need to add a new sheet or delete.
Also, to decide on opening or closing, I pass it through an IF statement in the line below. Can I use an Array(Codenames).count to switch the 6?
Code:
For Each Sh In Sheets(Array(Sheet5.Name, Sheet12.Name, Sheet2.Name, Sheet3.Name, Sheet33.Name, Sheet34.Name))
If Sh.Visible = xlSheetVeryHidden Then I = I + 1
Next Sh
If I = 6 Then
Full code:
Code:
Private Sub HideUnAdminSheets()
Dim Password As String, PasswordEnter As String
Password = "******"
Application.ScreenUpdating = False
I = 0
For Each Sh In Sheets(Array(Sheet5.Name, Sheet12.Name, Sheet2.Name, Sheet3.Name, Sheet33.Name, Sheet34.Name))
If Sh.Visible = xlSheetVeryHidden Then I = I + 1
Next Sh
If I = 6 Then
Retry:
PasswordEnter = InputBox("Please enter the admin password.")
Select Case LCase(PasswordEnter)
Case LCase(Password)
For Each Sh In Sheets(Array(Sheet5.Name, Sheet12.Name, Sheet2.Name, Sheet3.Name, Sheet33.Name, Sheet34.Name))
Sh.Visible = True
Next Sh
Sheet1.Activate
Case Else
RetryPassword = MsgBox("Would you like to retry?", vbYesNo)
Select Case RetryPassword
Case vbYes
GoTo Retry
Case vbNo
Exit Sub
End Select
End Select
Else
For Each Sh In Sheets(Array(Sheet5.Name, Sheet12.Name, Sheet2.Name, Sheet3.Name, Sheet33.Name, Sheet34.Name))
Sh.Visible = xlSheetVeryHidden
Next Sh
Sheet1.Activate
End If
Application.ScreenUpdating = True
End Sub