GLower0617
New Member
- Joined
- Oct 1, 2010
- Messages
- 17
I found this code searching forums and I have a specific use for it and I am trying to get it to function. I have only made minor changes to it so that it recognized the user row to determine which sheets to unlock. The idea is to prompt for username and password and then unhide the sheets that that particular user has access to. It matches the username in the user name column and then unhides the sheets that are listed in the same row as the username. I have it fully functioning now except that it will not unhide the last sheet in the loop. If there is only 1 sheet that the user is allowed to have access to then it will not unhide it as it sees it as the last sheet in the row. Not sure why. Any help is appreciated. Below is the sheet and the code.
Gary
[TABLE="class: grid, width: 626"]
<colgroup><col><col><col><col><col span="5"></colgroup><tbody>[TR]
[TD]User Name
[/TD]
[TD]Password[/TD]
[TD]Sheet[/TD]
[TD]Sheet[/TD]
[TD]Sheet[/TD]
[TD]Sheet[/TD]
[TD]Sheet[/TD]
[TD]Sheet[/TD]
[TD]Sheet
[/TD]
[/TR]
[TR]
[TD]PlantMgr[/TD]
[TD="align: right"]0000
[/TD]
[TD]Roster
[/TD]
[TD]Leadership[/TD]
[TD]A-Crew[/TD]
[TD]B-Crew[/TD]
[TD]C-Crew[/TD]
[TD]D-Crew[/TD]
[TD]UserList
[/TD]
[/TR]
[TR]
[TD]ProdSup[/TD]
[TD="align: right"]1111[/TD]
[TD]Roster[/TD]
[TD]Leadership[/TD]
[TD]A-Crew[/TD]
[TD]B-Crew[/TD]
[TD]C-Crew[/TD]
[TD]D-Crew[/TD]
[TD]UserList[/TD]
[/TR]
[TR]
[TD]QualSup[/TD]
[TD="align: right"]2222
[/TD]
[TD]Roster
[/TD]
[TD]Quality[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]TeamLead1[/TD]
[TD="align: right"]3333
[/TD]
[TD]Roster[/TD]
[TD]A-Crew[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]TeamLead2[/TD]
[TD="align: right"]4444[/TD]
[TD]Roster[/TD]
[TD]B-Crew[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]TeamLead3[/TD]
[TD="align: right"]5555[/TD]
[TD]Roster[/TD]
[TD]C-Crew[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]TeamLead4[/TD]
[TD="align: right"]6666[/TD]
[TD]Roster
[/TD]
[TD]D-Crew[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
</tbody>[/TABLE]
Gary
[TABLE="class: grid, width: 626"]
<colgroup><col><col><col><col><col span="5"></colgroup><tbody>[TR]
[TD]User Name
[/TD]
[TD]Password[/TD]
[TD]Sheet[/TD]
[TD]Sheet[/TD]
[TD]Sheet[/TD]
[TD]Sheet[/TD]
[TD]Sheet[/TD]
[TD]Sheet[/TD]
[TD]Sheet
[/TD]
[/TR]
[TR]
[TD]PlantMgr[/TD]
[TD="align: right"]0000
[/TD]
[TD]Roster
[/TD]
[TD]Leadership[/TD]
[TD]A-Crew[/TD]
[TD]B-Crew[/TD]
[TD]C-Crew[/TD]
[TD]D-Crew[/TD]
[TD]UserList
[/TD]
[/TR]
[TR]
[TD]ProdSup[/TD]
[TD="align: right"]1111[/TD]
[TD]Roster[/TD]
[TD]Leadership[/TD]
[TD]A-Crew[/TD]
[TD]B-Crew[/TD]
[TD]C-Crew[/TD]
[TD]D-Crew[/TD]
[TD]UserList[/TD]
[/TR]
[TR]
[TD]QualSup[/TD]
[TD="align: right"]2222
[/TD]
[TD]Roster
[/TD]
[TD]Quality[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]TeamLead1[/TD]
[TD="align: right"]3333
[/TD]
[TD]Roster[/TD]
[TD]A-Crew[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]TeamLead2[/TD]
[TD="align: right"]4444[/TD]
[TD]Roster[/TD]
[TD]B-Crew[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]TeamLead3[/TD]
[TD="align: right"]5555[/TD]
[TD]Roster[/TD]
[TD]C-Crew[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]TeamLead4[/TD]
[TD="align: right"]6666[/TD]
[TD]Roster
[/TD]
[TD]D-Crew[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
</tbody>[/TABLE]
Code:
Private Sub Workbook_Open()
Dim Sh As Worksheet
Dim UserName As String
Dim Password As String
Dim ThisCell As Range
Dim UserRow As Long
Dim C As Long
For Each Sh In ThisWorkbook.Worksheets
If Sh.Name <> "Roster" Then
Sh.Visible = xlSheetVeryHidden
End If
Next Sh
UserName = InputBox("Please enter Username")
Password = InputBox("Please enter password")
For Each ThisCell In Sheets("UserList").Range("A2:A" & Sheets("UserList").Range("A50000").End(xlUp).Row)
If UCase(ThisCell.Value) = UCase(UserName) And UCase(ThisCell.Offset(, 1).Value) = UCase(Password) Then
MsgBox "Access Granted"
For C = 3 To 11
UserRow = ThisCell.Row
If ThisCell.Offset(, C).Value <> "" Then
Sheets(Sheets("UserList").Cells([UserRow], C).Value).Visible = xlSheetVisible
End If
Next C
Exit Sub
End If
Next ThisCell
MsgBox "Access Denied"
ThisWorkbook.Close
End Sub