Lists

HRDataFool

New Member
Joined
Oct 24, 2003
Messages
20
I am preparing a multi-departmental spreadsheet and would like to have it set up so that the manager can key in their dpeartment id and then have only their employees populate. Some of the information is confidential and managers should only be able to see who reports to them. How can I do this?
 

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.
I setup a file whereby the manager/vp would log on with a username, the vba would check a list to make sure the person was on the list. Then if "passed" they entered a password, which was checked against another list, and if approved, then only their workers would show up in a resultant table.

Is this what you are looking for?
 
Upvote 0
I sent you an email (with attachment) to make sure this is the direction you want to go. If this is going to work, I will post more here as well to explain.
 
Upvote 0
For this demo there are three pages: Login, ShowData and Admin. Only the Login worksheet is visible. After logging in correctly, the Login worksheet hides, and the ShowData worksheet is visible. On ShowData, the user clicks on a cell to view data only applicable to his/her team.

Here is the Admin page setup for doing this:
DoubleEntryDisplayVBAposted.xls
ABCDEFGH
1LastNamePassword
2AAAA1111
3ABCD1234LastNamePassword
4BBBB2222UserPeterSimonThesecomefromInputBoxes
5JohnsonJakeCheckPeterSimon
6PeterSimon
7RefNameTopic
81ABCDABCD
92ABCDABCDSt
103ABCDABCDBox
114ABCDABCDTop
125JohnsonJohnson
136JohnsonJohnsonSt
147JohnsonJohnsonBox
158JohnsonJohnsonTop
169AAAAAAAA
1710AAAAAAAATop
1811AAAAAAAABottom
1912BBBBBBBB
2013BBBBBBBBTop
2114PeterPeter1
2215PeterPeter2
2316PeterPeter3
2417PeterPeter4
2518PeterPeter5
Admin


-----------------

The formula in F5 is:

INDEX(PWList,MATCH($H$4,LName,),MATCH($H$3,$A$1:$B$1,))

G5:

INDEX(PWList,MATCH($H$4,LName,),MATCH($I$3,$A$1:$B$1,))

Named ranges:

PWList: =OFFSET(Admin!$A$1,0,0,COUNTA(Admin!$A:$A),2)
LName: =Admin!$A$1:$A$6

For each name in Column A, there is an associated named range in E, to be used in the formulas and in the VBA code.
 
Upvote 0
Here is the code for the sheets in the general modules

Code:
Sub UserPassword()
    Dim LastName As String, PassWord As String, myName As String
Application.ScreenUpdating = False
    ActiveWorkbook.Sheets("Admin").Visible = True
    ActiveWorkbook.Sheets("Admin").Activate
    myName = InputBox("Enter Last Name")
    If myName = "" Then
        ActiveWorkbook.Sheets("Admin").Visible = False
        Exit Sub
    Else
    End If

    Sheets("Admin").Range("H4").Value = myName
    
'MsgBox Application.WorksheetFunction.VLookup(Sheets("Passwords").Range("H4").Value, Range("A2:A6"), 1, True)
    If Application.WorksheetFunction.VLookup(Sheets("Admin").Range("H4").Value, Range("A2:A6"), 1, True) = Sheets("Admin").Range("H4").Value Then
        Sheets("Admin").Range("I4").Value = InputBox("Enter Password")
        If Sheets("Admin").Range("I5").Value = Sheets("Admin").Range("I4").Value Then
            Sheets("ShowData").Range("B2").Value = Sheets("Admin").Range("H4").Value
            ActiveWorkbook.Sheets("ShowData").Visible = True
            ActiveWorkbook.Sheets("Intro").Visible = False
            ActiveWorkbook.Sheets("Admin").Visible = False
            ActiveWorkbook.Sheets("ShowData").Select
        Else:
            ActiveWorkbook.Sheets("Admin").Visible = False
            MsgBox ("You have entered wrong Password")
        End If
    Else
        ActiveWorkbook.Sheets("Admin").Visible = False
        MsgBox ("Your Name is not listed")
    End If
Application.ScreenUpdating = True
End Sub

Code:
Sub ValidationTest()
    Dim myName As String
    Dim ABCDList As Range
    Dim JohnsonList As Range
    Dim AAAAList As Range
    Dim BBBBList As Range
    Dim PeterList As Range
    
    With Range("B3")
        .Font.Bold = True
        .Font.Size = 12
        .Font.Color = vbRed
        .Interior.Color = vbYellow
        .HorizontalAlignment = xlLeft
        .VerticalAlignment = xlCenter
    End With
    myName = Sheets("ShowData").Range("B2").Value
    Select Case myName
        Case "ABCD"
            Sheets("ShowData").Range("B3").Select
            With Selection.Validation
                .Delete
                .Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:= _
                    xlBetween, Formula1:="=ABCDList"
                .IgnoreBlank = True
                .InCellDropdown = True
            End With
        Case "Johnson"
            Sheets("ShowData").Range("B3").Select
            With Selection.Validation
                .Delete
                .Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:= _
                    xlBetween, Formula1:="=JohnsonList"
                .IgnoreBlank = True
                .InCellDropdown = True
            End With
        Case "Peter"
            Sheets("ShowData").Range("B3").Select
            With Selection.Validation
                .Delete
                .Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:= _
                    xlBetween, Formula1:="=PeterList"
                .IgnoreBlank = True
                .InCellDropdown = True
            End With
        Case "AAAA"
            Sheets("ShowData").Range("B3").Select
            With Selection.Validation
                .Delete
                .Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:= _
                    xlBetween, Formula1:="=AAAAList"
                .IgnoreBlank = True
                .InCellDropdown = True
            End With
        Case "BBBB"
            Sheets("ShowData").Range("B3").Select
            With Selection.Validation
                .Delete
                .Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:= _
                    xlBetween, Formula1:="=BBBBList"
                .IgnoreBlank = True
                .InCellDropdown = True
            End With
    End Select
End Sub

Code:
Sub EndSession()
    Application.ScreenUpdating = False
    ActiveWorkbook.Sheets("Intro").Visible = True
    ActiveWorkbook.Sheets("ShowData").Range("B2").ClearContents
    ActiveWorkbook.Sheets("ShowData").Range("B3").Clear
    ActiveWorkbook.Sheets("ShowData").Range("B3").Validation.Delete

    ActiveWorkbook.Sheets("ShowData").Visible = False
    Application.ScreenUpdating = True
End Sub

This following code goes into the Workbook module:

Code:
Private Sub Workbook_BeforeClose(Cancel As Boolean)
    Sheets("ShowData").Visible = False
    ActiveWorkbook.Close True
End Sub
 
Upvote 0
Just to let you know, I emailed you revisions so that it will accommodate expansion in names of managers, people under each manager, and a database to pull data from. I also changed from Data Validation to filling all the cells.

I managed to change this to make it more flexible. I added another worksheet, named "Base" that will house your main data.

1. Names and Passwords will continue on Admin sheet in columns A and B. I defined a dynamic range to accommodate additions without changing names:

LName =OFFSET(Admin!$A$1,0,0,COUNTA(Admin!$A:$A),1)
PWList =OFFSET(Admin!$A$1,0,0,COUNTA(Admin!$A:$A),2)

2. Each name then is presented in a separate column with people underneath each, also using dynamic names to accommodate more people:

AAAAList =OFFSET(Admin!$H$2,0,0,COUNTA(Admin!$H:$H)-1,1)
ABCDList =OFFSET(Admin!$I$2,0,0,COUNTA(Admin!$I:$I)-1,1)
BBBBList =OFFSET(Admin!$J$2,0,0,COUNTA(Admin!$J:$J)-1,1)
JohnsonList =OFFSET(Admin!$K$2,0,0,COUNTA(Admin!$K:$K)-1,1)
PeterList =OFFSET(Admin!$L$2,0,0,COUNTA(Admin!$L:$L)-1,1)

3. If you add a new manager, then add it in column A Ralph), and after the last used column (i.e. after PeterList). Then add one new dynamic range, using these formulas (i.e. RalphList =OFFSET(Admin!$M$2,0,0,COUNTA(Admin!$M:$M)-1,1)

4. I changed the macros so that it will put the names in Column B, starting with B4, and fill down as appropriate (no longer Data Validation dropdown in B3). Then I added some column headings in row 3 (i.e. Category 1, Category2...). These refer to the columns in the new worksheet "Base"; the full data is named dynamically

myDataBase =OFFSET(Base!$A$1,0,0,COUNTA(Base!$A:$A),COUNTA(Base!$1:$1))

Thus, you can add columns as needed and will always be in the data. be sure to include new columns on the ShowData worksheet

That will be the basis for pulling data into the ShowData worksheet. You can set up formulas and then have the macro place them each time you run the program. Right now the "end" macro clears all cells in the dynamic named range,

DataList =OFFSET(ShowData!$B$4,0,0,COUNTA(ShowData!$B:$B)-2,COUNTA(ShowData!$3:$3))

That way, it will always be cleared. Another approach might be to hide those columns with formulas always present, and then use a macro to hide the columns, until the next login, and then have the login macro also unhide the columns.

At least you should have a workable solution.

HTH
 
Upvote 0
Here is the modified code to handle the changes in the worksheets:

Code:
Sub UserPassword()
    Dim LastName As String, PassWord As String, myName As String
Application.ScreenUpdating = False
    ActiveWorkbook.Sheets("Admin").Visible = True
    ActiveWorkbook.Sheets("Admin").Activate
    myName = InputBox("Enter Last Name")
    If myName = "" Then
        ActiveWorkbook.Sheets("Admin").Visible = False
        Exit Sub
    Else
    End If

    Sheets("Admin").Range("D2").Value = myName
    
'MsgBox Application.WorksheetFunction.VLookup(Sheets("Passwords").Range("D2").Value, Range("A2:A6"), 1, True)
    If Application.WorksheetFunction.VLookup(Sheets("Admin").Range("D2").Value, Range("A2:A6"), 1, True) = Sheets("Admin").Range("D2").Value Then
        Sheets("Admin").Range("E2").Value = InputBox("Enter Password")
        If Sheets("Admin").Range("E3").Value = Sheets("Admin").Range("E2").Value Then
            Sheets("ShowData").Range("B2").Value = Sheets("Admin").Range("D2").Value
            ActiveWorkbook.Sheets("ShowData").Visible = True
            ActiveWorkbook.Sheets("Intro").Visible = False
            ActiveWorkbook.Sheets("Admin").Visible = False
            ActiveWorkbook.Sheets("ShowData").Select
        Else:
            ActiveWorkbook.Sheets("Admin").Visible = False
            MsgBox ("You have entered wrong Password")
        End If
    Else
        ActiveWorkbook.Sheets("Admin").Visible = False
        MsgBox ("Your Name is not listed")
    End If
'   This calls the next macro for filling in the data
    ViewData
Application.ScreenUpdating = True
End Sub


Sub ViewData()
    Dim myName As String
    Dim ABCDList As Range
    Dim JohnsonList As Range
    Dim AAAAList As Range
    Dim BBBBList As Range
    Dim PeterList As Range
    
    myName = Sheets("ShowData").Range("B2").Value
    Select Case myName
        Case "AAAA"
            Sheets("Admin").Range("AAAAList").Copy Sheets("ShowData").Range("B4")
        Case "ABCD"
            Sheets("Admin").Range("ABCDList").Copy Sheets("ShowData").Range("B4")
        Case "BBBB"
            Sheets("Admin").Range("BBBBList").Copy Sheets("ShowData").Range("B4")
        Case "Johnson"
            Sheets("Admin").Range("JohnsonList").Copy Sheets("ShowData").Range("B4")
        Case "Peter"
            Sheets("Admin").Range("PeterList").Copy Sheets("ShowData").Range("B4")
    End Select

End Sub

Sub EndSession()
    Application.ScreenUpdating = False
    On Error Resume Next
    ActiveWorkbook.Sheets("Intro").Visible = True
    ActiveWorkbook.Sheets("ShowData").Range("B2").ClearContents

    Sheets("ShowData").Range("DataList").ClearContents
    ActiveWorkbook.Sheets("ShowData").Visible = False
    On Error GoTo 0
    Application.ScreenUpdating = True
End Sub
 
Upvote 0

Forum statistics

Threads
1,215,053
Messages
6,122,882
Members
449,097
Latest member
dbomb1414

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