First, there are three Sheet.Visible conditions; Visible, hidden, and VeryHidden. Users can unhide Hidden sheets with the Excel Menu, but not VeryHidden.
This is a simple to understand algorithm:
Option Explicit
Private Sub Workbook_Open()
ShowHideSheets
End Sub
Private Sub ShowHideSheets()
Dim Sht As Worksheet
Dim AlwaysShow As String
AlwaysShow = "Main, Sheet1, Don't Hide Me"
'List the names of all sheets that should never be hidden in AlwaysShow.
'there must always be at least one sheet visible in the Workbook.
For Each Sht In Sheets
If Not InStr(AlwaysShow, Sht.Name) Then
Sht.Visible = xlVeryHidden
End If
Next
Select Case Application.UserName
Case "Administrator": ShowForAll
Case "Harry": ShowForHarry
Case "Jane": ShowForJane
Case "Bill": ShowForBill
End Select
End Sub
Private Sub ShowForAll()
Sheets("Total Revenue").Visible = xlVisible
Sheets("Office A").Visible = xlVisible
Sheets("Office B").Visible = xlVisible
Sheets("Office C").Visible = xlVisible
End Sub
Private Sub ShowForHarry()
'Sheets("Total Revenue").Visible = xlVisible
Sheets("Office A").Visible = xlVisible
Sheets("Office B").Visible = xlVisible
Sheets("Office C").Visible = xlVisible
End Sub
Private Sub ShowForJane()
Sheets("Total Revenue").Visible = xlVisible
'Sheets("Office A").Visible = xlVisible
Sheets("Office B").Visible = xlVisible
'Sheets("Office C").Visible = xlVisible
End Sub
Private Sub ShowForBill()
Sheets("Total Revenue").Visible = xlVisible
'Sheets("Office A").Visible = xlVisible
'Sheets("Office B").Visible = xlVisible
Sheets("Office C").Visible = xlVisible
End Sub
The Workbook_Open sub runs every time the book is opened. It merely runs the ShowHide Sub.
The ShowHide Sub first, hides all the worksheets, then, depending on the login UserName, calls one of the ShowForUser-Name Subs.
Sub SHowAll is the Template that you copy for each User's ShowFor sub.
All the ShowFor-UserName Subs are identical to the ShowForAl Sub, that way you can copy it for each user and change the "Name" to suit. Note that the "
Sheets("Sheet-name").Visible" lines that are commented out will not be shown to the User
The KeyWord "Private" keeps those Subs out of the Macro list in the Excel Menus