VBA code to cycle through each Pivot Filter Item

Vincodi

New Member
Joined
Jan 12, 2018
Messages
1
Hi. I am creating a slide based off the data in a pivot table. The Pivot table has 2 filters, "Market" & "HH Characteristic". I need to create a slide for each HH Characteristic within each Market. For example, there are 3 markets and 5 characteristics. For each market, I must create a slide with the data from each of the characteristics. So in this example I would need to create 15 slides. Instead of doing this manually, I am trying to create a macro that will automatically select the Market then a characteristic and create a slide, then the next characteristic and create a slide until there are no more characteristics left. AT that point, I want it to select the next market and repeat for each of the characteristics unitl there are no more Markets left. I already have an idea of how to get the slide created, so you needn't worry about that aspect of it. What I am hoping you can help me with is figuring out how to get VBA to select the Market filter items and the Characteristic filter items and out the corresponding data on the pivot table so my slide macro creation macro can take it from there.

Here's an example of the script I have so far. It seems to be moving through the filter items, but not updating the pivot table with the data. Thanks in advance for any help you can provide.

Sub Cycle_Filters()
Application.ScreenUpdating = False

Dim pt As PivotTable
Dim pim As PivotItem
Dim pic As PivotItem
Dim pfm As PivotField
Dim pfc As PivotField

For Each pt In ActiveSheet.
Set pfm = pt.PivotFields("Market")
Set pfc = pt.PivotFields("HH Characteristic")


For Each pim In pfm.PivotItems
pim.Visible = True
For Each pic In pfc.PivotItems

Next pic
Next pim
Next pt
Application.ScreenUpdating = True
End Sub
 

Excel Facts

Why are there 1,048,576 rows in Excel?
The Excel team increased the size of the grid in 2007. There are 2^20 rows and 2^14 columns for a total of 17 billion cells.

Forum statistics

Threads
1,223,886
Messages
6,175,196
Members
452,616
Latest member
intern444

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