Password Protecting Individual Sheets

How can the code be adjusted so that the user would be able to see more than just one sheet? For example I have a speadsheet that will have two sheets that each user will need to see.
Welcome to the MrExcel bopard!

See if this more flexible approach is useful to you. For my test workbook I have ..

- A sheet called 'Public' that anybody can view. This sheet could be blank or have a message about not being able to view other sheets without providing appropriate login details etc.

- A 'LogIn' sheet somewhat similar to the previous example in this thread except that the sheets that a standard 'User' can view (apart from 'Public') are listed in column B separated by a "/". So you can see that BenSmith has access to only one other sheet, whereas BobB has access to 4 other sheets besides 'Public'.

- Three levels of access (though you don't need to use 'Manager' if you don't want).
A 'User' can only view quite restricted sheets as described above.
A 'Manager' can view all sheets except 'Login'.
An 'Admin' can view all sheets.

So here is my Login sheet from which you can deduce my worksheet names in addition to 'LogIn' and 'Public'.

Excel Workbook
ABCD
1UsernameAllowed Sheet NamesStatusPassword
2AdminAdminadmin
3JimJManagerabc
4JohnSManagerdef
5JenJJen/SummaryUserjen
6KenKKen/Profit & LossUserkkk
7BobBBob/Ben/Jen/SummaryUserbob
8BenSmithBenUserben
LogIn



And here are my 'ThisWorkbook' codes.

VBA Code:
Private Sub Workbook_BeforeClose(Cancel As Boolean)
  Dim ws As Worksheet
  
  Sheets("Public").Visible = True
  For Each ws In Worksheets
    If ws.Name <> "Public" Then ws.Visible = xlSheetVeryHidden
  Next ws
  ThisWorkbook.Save
End Sub

Private Sub Workbook_Open()
  Dim user As String, pwd As String, Correctpwd As String, Status As String
  Dim ct As Long, LR As Long, i As Long
  Dim C As Range
  Dim ws As Worksheet
  Dim AllowedSheets
  
  LR = Sheets("LogIn").Cells(Rows.Count, "A").End(xlUp).Row
  user = InputBox("Enter your UserName")
  Set C = Worksheets("LogIn").Range("$A1:$A" & LR).Find(What:=user, LookIn:=xlValues, MatchCase:=False, SearchFormat:=False)
  If Not C Is Nothing Then
    Status = C.Offset(, 2)
    Correctpwd = C.Offset(, 3)
    Do While ct < 3 And pwd <> Correctpwd
      pwd = InputBox("Enter Password: " & 3 - ct & " tries left")
      ct = ct + 1
    Loop
    If pwd = Correctpwd Then
      Application.ScreenUpdating = False
      If Status = "User" Then
        AllowedSheets = Split(C.Offset(, 1).Value, "/")
        For i = 0 To UBound(AllowedSheets)
          Sheets(AllowedSheets(i)).Visible = True
        Next i
      Else
        For Each ws In Worksheets
        ws.Visible = True
        Next ws
      End If
      If Status <> "Admin" Then
        Sheets("LogIn").Visible = xlVeryHidden
      End If
      Application.ScreenUpdating = True
    End If
  Else
    MsgBox "Not a valid user, access to other sheets denied"
  End If
End Sub
 
Last edited:
Upvote 0

Excel Facts

Create a Pivot Table on a Map
If your data has zip codes, postal codes, or city names, select the data and use Insert, 3D Map. (Found to right of chart icons).
lynne1014,

Take a look at my recent response to a similar post and see if that helps any.

LOOK HERE

Tony
 
Upvote 0
I have tried your code and is not working even though I have set up my LogIn sheet exactly as you have suggested. I wanted the the user to have access to their individual sheet and the sample sheet, while the manager has access to all sheets and the Admin can modify (add or delete user to the LogIn sheet. My workbook name is Asset Register, and you can see the all the sheets in the workbook on the LogIn sheet except the Dropdown sheet that no one should have access but the Admin. Any help


Sample.xlsm
ABCD
1UsernameSheet NameStatusPassword
2Adminadminadmin
3ADFINManagerADFASST
4BENCPC BENINUserbenr01
5SENCPC SENEGALUsersenr01
6MLICPC MALIUsermlir01
7BFACPC BURKINA FASOUserbfar01
8NERCPC NIGERUsernerr01
9LBRCPC LIBERIAUserlbrr01
10MRTCPC MAURITANIAUsermrtr01
11RWACPC RWANDAUserrwar01
12NGACPC NIGERIAUserngar03
13ZMBCPC ZAMBIAUserzmbr03
14MWICPC MALAWIUsermwir02
15TZACPC TANZANIAUsertzar02
16UGACPC UGANDAUserugar02
17ZWECPC ZIMBABWEUserzwer02
18KENCPC KENYAUserkenr02
Login
 
Upvote 0
I have tried your code ..
Not very precise. Is that my code from post #11, or my code from either of 2 earlier posts, or the code suggested by Snakehips?

Assuming you mean post #11 ..

1. What do you mean by the "Dropdown sheet"?

2. Can you confirm that the code was placed in the ThisWorkbook module and not a Standard Module or Worksheet Module?

3. Did you change the code in any way to suit your own circumstances? If so, can you post the code you have actually used? Also see my signature block for how to post code. Code tags are simplest.

4. When you open your Workbook, do you get a prompt asking for your UserName?

5. Do you have a worksheet called "Public" per my description?
 
Upvote 0

Forum statistics

Threads
1,216,059
Messages
6,128,542
Members
449,457
Latest member
ncguzzo

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top