So I have a pivot table and I'd like it to always re-populate with the rows always collapsed when data is refreshed or the data range changed.
Basically I have row labels for Region, State, DMA in that sequence in my pivot table. If a new region shows up, all of the States/DMA/s in the pivot table show up and are not collapsed, same with new states.
What I'd like to do is figure out a way I can go through all of the values in the Region pivot item and set the "ShowDetail" equal to false.
I can hardcode it using code similar to that below but I'm wary of that as it won't address new regions/states/DMA's.
I'm sure there must be a way to count the number of regions in the "region" pivot item and loop through to set them all to ShowDetail=False, but I can't figure out how to do a count on the pivotitem or pivotfield.
Basically I have row labels for Region, State, DMA in that sequence in my pivot table. If a new region shows up, all of the States/DMA/s in the pivot table show up and are not collapsed, same with new states.
What I'd like to do is figure out a way I can go through all of the values in the Region pivot item and set the "ShowDetail" equal to false.
I can hardcode it using code similar to that below but I'm wary of that as it won't address new regions/states/DMA's.
Code:
ActiveSheet.PivotTables("PivotTable1").PivotFields("Region").PivotItems( _
"East").ShowDetail = False
I'm sure there must be a way to count the number of regions in the "region" pivot item and loop through to set them all to ShowDetail=False, but I can't figure out how to do a count on the pivotitem or pivotfield.