Last week, Angella emailed me, to ask if there was a way to create a copy of a pivot table, for each item in a report filter.
I suggested that she use a built-in pivot table feature, which is designed to do that – Show Report Filter Pages. The instructions for using this feature are shown below.
However, this built-in feature only copies the pivot table to a new sheet – it doesn’t copy any other content from the original sheet. Angella wanted the pivot table, and she wanted all the other content too.
So, I created a macro that will copy the original sheet, name the copied sheet, and select the pivot item in the copied sheet’s pivot table. You can see the sample code on my Contextures site.
If you just need a copy of the pivot table, you can do the job quickly and easily with the Show Report Filter Pages feature.
Copy Pivot Table with Show Report Filter Pages
To create a quick copy of a pivot table, for each item in a Report Filter field, follow these steps:
- Select a cell in the pivot table (the pivot table must have at lease one Report Filter)
- On the Ribbon, under the PivotTable Tools tab, click the Options tab
- At the left, click Options, then click Show Report Filter Pages
- In the Show Report Filter Pages dialog box, select one of the filters, and click OK
- A new worksheet will be added for each* pivot item, named for the pivot item. (*see exceptions below)
Note: If a sheet with the item’s name already exists, another sheet will be added, with a number added at the end.
Report Filter Page Exceptions
When you run the Show Report Filter Pages command, it might not create a new sheet for each item in the Report Filter. The results will be affected by
- the setting for Select Multiple Items
- which items are currently selected in filter
Select Multiple Items Turned Off
- If (All) is selected, a sheet should be created for each item.
- If a specific item is selected, a sheet will not be created for that item. I guess that Excel assumes that since you already have a pivot table with that item’s data, you don’t need another one.
Select Multiple Items Turned On
- If (All) is selected, a sheet should be created for each item.
- If one item is selected, a sheet will be created for that item only.
- If two or more items are selected (Multiple Items), a sheet will be created for each selected item.
Note: Select Multiple Items is turned off in the pivot table copies, even if it is turned on in the original pivot table.
Use VBA to Copy the Entire Worksheet
If you want to copy all the other content from the original worksheet, along with the pivot table, you can sample code on my Contextures site on my Contextures site. My code adds a “PT_” prefix to the sheets, and deletes any existing “PT_” sheets, if necessary.
___________________
Ms. Debra.
How could I update the related Pivot Tables when Parent Pivot Table data changes its values or changes its number of rows (expand or contract the range)?
Thanks a lot for your answer.
Carlos
Hi Debra
I have a similar requirement to this however I want my VB code to copy each filtered group of data to go to the worksheet named the same as the filter.
eg: filter column A “BkHireDPC” results to be copied to worksheet of the same name then loop back and copy next value “BusTech” results to BusTech worksheet. On each worksheet I only want user to be able to see their data.
Peter, you could modify the code slightly, so it pastes onto an existing sheet with the same name, instead of creating a new sheet.
However, if you only want users to see their own data, you should create a new workbook for each person, and paste the filtered pivot table there, as VALUES. If you leave it as a pivot table, they could double-click the Grand Total cell, and recreate the source data.
Hi,
I have created a pivot which is created by power query and I tried to create multiple worksheets from the filter values but it shows an error but the code runs fine in the normal pivot, could you please help me to find the solution.