VBA to Drill Down on Pivot Table and Rename Sheets

welshraz

New Member
Joined
Apr 29, 2016
Messages
39
Office Version
  1. 365
Platform
  1. Windows
Hello,

I have a small pivot table with data on various UK regions. Each week I need to drill down on each of the regions and rename each of the new tabs with the specified region name. There are several other pivot tables on the sheet, but only one will have this process attached to it. The region names are different every week, but there will be no more than 10 at a time.

I am doing this manually at the moment, but would like to add it on to an existing automation. I'm having trouble because the amount of regions in the list changes each week.

Sample1.xlsx
F
11
Pivots


Sample1.xlsx
B
18YOU1591420
Data


The end product should look like this:
1643031112579.png
 

Excel Facts

Select all contiguous cells
Pressing Ctrl+* (asterisk) will select the "current region" - all contiguous cells in all directions.
what happens next week, as you drill down a second "Montmouth", rename it "Monmouth(2)" or overwrite the 1st ?
 
Upvote 0
are you experienced in VBA ?
This in Contextures and here you find 3 versions Excel Pivot Table DrillDown Show Details
Thanks for the recommendation. I have managed to pull together what I need.

Just in case anyone is interested. The code I used to create a new tab for each line in the pivot, and then rename is:

VBA Code:
Sub TabsForProjects()

Dim pItemCell As Range
Dim pField As PivotField
Dim pT As PivotTable
Dim pItem As PivotItem
Dim rngData As Range

 Set pT = Sheets("Overview").PivotTables("Total")
 Set pField = pT.PivotFields("Total for Tabs")

For Each pItemCell In pField.DataRange
    If pItemCell.Value <> "(blank)" Then
        Set pItem = pField.PivotItems(pItemCell.Value)
        pItem.DataRange.ShowDetail = True
        ActiveSheet.Name = pItem.Name
    End If
Next pItemCell
End Sub
 
Upvote 0
Solution

Forum statistics

Threads
1,214,918
Messages
6,122,243
Members
449,075
Latest member
staticfluids

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