user lists part 2

MarkRush

New Member
Joined
Mar 6, 2018
Messages
28
so a while back a very knowledgeable user DMT32 helped me update his macro to meet my needs and all of a sudden it started having issues. Works great for users defined as admin but everyone else gets a Subscript out of range error. The Macro does do what its supposed to do, but the error is a nuisance hope someone can help

The original post was here

https://www.mrexcel.com/forum/excel...hide-worksheets-based-windows-user-names.html

my code is here

Code:
Private Sub Workbook_Open()
    Dim Admin As Boolean
    Dim msg As Variant
    Dim LastCol As Integer, C As Integer
    Dim rng As Range
    Dim sh As Worksheet, Userlist As Worksheet


    


    On Error GoTo myerror
     
        ThisWorkbook.Sheets(HomeSheet).Visible = xlSheetVisible
       
        HideSheets


        Set Userlist = UserTable("User List")
       
        With Userlist
            .Unprotect Password:=shPassword
            lastrow = .Cells(.Rows.Count, "A").End(xlUp).Row
            LastCol = .Cells(1, .Columns.Count).End(xlToLeft).Column
            Set rng = .Range("A2:A" & lastrow)
        End With




    'check valid user
    If IsValidUser(rng, Admin) Then
            Application.ScreenUpdating = False
            'Admin User unhide all sheets
            If Admin Then
                For Each sh In ThisWorkbook.Worksheets
                    sh.Visible = xlSheetVisible
                    sh.Unprotect Password:=shPassword
                Next sh
            Else
                'unhide user sheets
                With Userlist
                    For C = 3 To LastCol
                        If UCase(.Cells(rng.Row, C).Value) = "X" Then
                            With Sheets(.Cells(1, C).Value)
                                .Visible = xlSheetVisible
                                '.Unprotect Password:=shPassword
                            End With
                        End If
                    Next C
                   'If Len(shPassword) > 0 Then .Protect Password:=shPassword
                End With
            End If
            'activate home sheet
            Worksheets(HomeSheet).Activate
            
        Else
           'user Not Valid
    
            For C = 3 To LastCol
                If UCase(Userlist.Cells(2, C).Value) = "X" Then
                    With Sheets(Userlist.Cells(1, C).Value)
                        .Visible = xlSheetVisible
                        .Unprotect Password:=shPassword
                    End With
                End If
            Next C
'activate home sheet
            Worksheets(HomeSheet).Activate
            If Len(shPassword) > 0 Then Userlist.Protect Password:=shPassword


        End If
        
myerror:
Application.ScreenUpdating = True
If Err > 0 Then MsgBox (Error(Err)), 48, "Error"


Sheets("sf1").Visible = Hidden
[Min_Margin].Value = 0.3
Set ws = Sheets("Detailed Proposal")
With Sheets("Detailed Proposal")
.Protect Password:="password", AllowFormattingCells:="true", AllowFormattingColumns:="true", AllowFormattingRows:="true"
End With


Set ws = Sheets("configuration")
With Sheets("configuration")
.Protect Password:="password", AllowFormattingCells:="true", AllowFormattingColumns:="true", AllowFormattingRows:="true"
End With


Set ws = Sheets("Implementation Questionaire")
With Sheets("Implementation Questionaire")
.Protect Password:="password", AllowFormattingCells:="true", AllowFormattingColumns:="true", AllowFormattingRows:="true"
End With




End Sub

any help would be appreciated
 
Last edited:

Excel Facts

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying

Forum statistics

Threads
1,214,635
Messages
6,120,660
Members
448,975
Latest member
sweeberry

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