Power Query
July 11, 2016
Hi,
I have a pivot report that gets emailed out to different sales teams. I want to filter the report for a specific team and then lock the report before mailing so that the recipients can only see their specific information. I also want them to be able to maintain full pivot table functionality but just with their data.
I thought I had found a solution whereby I removed the ability to filter on the Team field in the report (see attached example file). The VBA in this file is as follows:
The Disable_Selection code removes the selection from the Team field (Ctrl+D runs)
Sub Disable_Selection()
Dim pt As PivotTable
Dim pf As PivotField
On Error Resume Next
Set pt = ActiveSheet.PivotTables(1)
Set pf = pt.PivotFields("Team")
pf.EnableItemSelection = False
End Sub
The Enable_Selection code adds back the selection from the Team field (Ctrl+E runs)
Sub Enable_Selection()
Dim pt As PivotTable
Dim pf As PivotField
On Error Resume Next
Set pt = ActiveSheet.PivotTables(1)
Set pf = pt.PivotFields("Team")
pf.EnableItemSelection = True
End Sub
If you look at the attached file it is filtered for team 03 and you can't select any other teams from the report filter in cell B1. However I have found a flaw, if you type 02 in cell B1 and press enter you will see that the data updates and you now see the information for team 02.
I have thought about protecting the worksheet but it becomes complicated as the users need to have the ability to access the field lists to add additional fields if required and to re-arrange the pivot layout by moving fields. Even if protect the sheet and select the Use PivotTable Reports option it doesn't give you the required functionality.
The attached file is just an example and not the actual report. In the actual report their are many more teams, many more data fields, and some recipients will get data for multiple selected teams.
Any ideas gratefully received.
Regards
Bax
Power Query
Power Pivot
Xtreme Pivot Tables
Excel for Decision Making
Excel for Finance
Excel Analysis Toolpak
Power BI
Excel
Word
Outlook
Excel Expert
Excel Customer Service
PowerPoint
November 8, 2013
There are a few workarounds:
You can try using the SelectionChange event to detect if the user selected the B2 cell and move away from that cell: (the code should be placed in Pivot sheet vba module)
If Not Intersect(Target, Me.Range("B2")) Is Nothing Then
Me.Range("B3").Select
End If
End Sub
Power Query
July 11, 2016
Hi Catalin,
Thanks for the response. I did think about something along the lines of what you have said however I want the user to be able to have pretty much full pivot functionality so for example they may move the Team field from the report filter section to the pivot table rows. In this instance referencing a specific cell in the code wouldn't work.
Cheers
Bax
Power Query
Power Pivot
Xtreme Pivot Tables
Excel for Decision Making
Excel for Finance
Excel Analysis Toolpak
Power BI
Excel
Word
Outlook
Excel Expert
Excel Customer Service
PowerPoint
November 8, 2013
I guess you don't want a team to see other teams data, you have other options.
For example, you can setup a login sheet, users will select the team and type the team password, using a simple code you can remove other teams data from the file. here is an example of hiding the sheets until macros are enabled, you can update it to setup a login sheet instead of the Info sheet.
Power Query
July 11, 2016
Hi Catalin,
I am not sure adding the code in your example will help me solve my issue above but it will be really really useful for lots of other things I can think of so thanks for that.
The issue I have is that all of the data for all teams is in the same source data table. If the user can simply enter another teams number in the Teams field and it returns that team's data then it seems there is nothing that can be done to prevent this. I think another option I may look at is using power query with a parameter for team. I can then just return the data for a specific team and then base the pivot on the PQ data table.
It is a shame because the solution I had is very simple and quick to invoke on a pivot table. It was great until someone pointed out that it can just simply be overwritten 🙂
Thanks
Bax
Power Query
Power Pivot
Xtreme Pivot Tables
Excel for Decision Making
Excel for Finance
Excel Analysis Toolpak
Power BI
Excel
Word
Outlook
Excel Expert
Excel Customer Service
PowerPoint
November 8, 2013
baxbax said
I am not sure adding the code in your example will help me solve my issue above ...If the user can simply enter another teams number in the Teams field and it returns that team's data then it seems there is nothing that can be done to prevent this.
Why not? If a team logs in with their team password, in the file will only be that team data, all other data should be removed by code. No matter what users will type, there will be no data for other teams.
1 Guest(s)