Try these 2 files for size. Open and allow macros
The files are identical except for their name
Currently the files are set to autosave when closed (temporary while still working on it)
Each file contains
- sheet("Data") - with all the data (set to VeryHidden)
- sheet("myData") - into which an individual manager's data is copied (set to VeryHidden)
- sheet("myPivot) - which contains the manager's own pivot table based on his "myData" (set to VeryHidden at time of opening)
When the files are opened
- only blank Sheet1 is visible AND
- a password is required (captured in a text box)
The files have different passwords (both have upper case first letter)
file "mike..." = Hisword
file "sueb..." = Herword
When the password has been entered, the code checks to see if "1st 4 chars of filename" + "password" matches pre-designated string.
If the string matches
- sheet myPivot is unhidden
- pivot table is immediately updated with managers data
- manager's data set is based on cell "A1" value which is currently = "1st 4 characters of file name"
In the example files the 2 managers' pivot includes details for different staff
At the moment this is not bomb proof (otherwises becomes a pain to work on) - need to protect the vba etc and prevent user saving changes etc.
I believe this goes a long way towards meeting your needs
- you may prefer (for data security reasons) to piecemeal the actual data rather than putting "all" in each
Let me know what you think and then I will tell you how to amend it to test it out on your own data
this is how a managers selections are grouped:
Manager = Sheets("myPivot").Range("A1").Value
Select Case UCase(Manager)
Case "MIKE"
With Sheets("Data")
Range(.Range("A1"), .Range("A1").SpecialCells(xlLastCell)).AutoFilter Field:=3, Criteria1:="=Joe", _
Operator:=xlOr, Criteria2:="=Peter"
End With
Case "SUEB"
With Sheets("Data")
Range(.Range("A1"), .Range("A1").SpecialCells(xlLastCell)).AutoFilter Field:=3, Criteria1:="=David", _
Operator:=xlOr, Criteria2:="=John"
End With
this is how the the selected data is copied into sheet myData and the pivot table refreshed
Sub CopyDataToMyData()
Sheets("data").Visible = True
Dim ws1 As Worksheet, ws2 As Worksheet, ws3 As Worksheet
Dim rPivot As Range
Dim Manager As String
Set ws1 = Sheets("Data")
Set ws2 = Sheets("myData")
Set ws3 = Sheets("myPivot")
'clears old pivot data area and replace with latest data
ws2.Cells.ClearContents
ws1.UsedRange.SpecialCells(xlCellTypeVisible).Copy Destination:=ws2.Range("a1")
'refresh the pivot table using latest data
Set rPivot = Range(ws2.Range("A1"), ws2.Range("A1").SpecialCells(xlLastCell))
ws3.PivotTables("MyPivot").ChangePivotCache ThisWorkbook.PivotCaches.Create(SourceType:=xlDatabase, SourceData:=rPivot)
ws3.PivotTables("MyPivot").RefreshTable
Call HideSheets
ws3.Range("A1").Select
this is the password control when the file is opened (driven via textbox on UserForm which is presented as the file opens)
Private Sub CommandButton1_Click()
Dim x As String
y = UCase(Left(ThisWorkbook.Name, 4))
x = TextBox1.Value
Select Case y & x
Case "MIKEHisword"
GoTo Approved
End Select
Select Case y & x
Case "SUEBHerword"
GoTo Approved
End Select
Rejected:
MsgBox "User/Password mismatch"
Exit Sub
Approved:
Sheets("myPivot").Visible = True
Sheets("Sheet1").Visible = False
UserForm1.Hide
Sheets("myPivot").Select
Sheets("myPivot").Range("A1").Value = y 'manager's name
Call Manager
Call CopyDataToMyData
End Sub
Bookmarks