Hi Guyz,
I am working with a Pivot. That has some 1000 project each having unique alpha numerical project codes and there budgets for the entire year.
I have grouped the multiple projects under Labs. So I want to filter the project codes in the pivot which in turn effects an Chart.
I tried to use macro recording but it returns a Macro with lot of lines pivot item ac039 = false and finally gives an error that the procedure is too large.
I got the below macro. But this un-ticks the project codes one by one and each time the entire report refreshes and the slicers run taking several hours.
I tried using manual update = true but i dont know whether it is kicking in or not. All i need is remove all filters and keep the project codes which I need to have. The project codes may vary from 1 to 10 project codes at a time.
<code style="margin: 0px;">ption Explicit
Sub FilterPivotItems()
Dim PT As PivotTable
Dim PTItm As PivotItem
Dim FiterArr()AsVariant
' use an array to select the items in the pivot filter you want to keep visible
FiterArr = Array("101","105","107")
' set the Pivot Table
Set PT = ActiveSheet.PivotTables("PivotTable3")
' loop through all Pivot Items in "Value" Pivot field
ForEach PTItm In PT.PivotFields("Value").PivotItems
IfNot IsError(Application.Match(PTItm.Caption, FiterArr,0))Then' check if current item is not in the filter array
PTItm.Visible =True
Else
PTItm.Visible =False
EndIf
Next PTItm
EndSub</code>
I am working with a Pivot. That has some 1000 project each having unique alpha numerical project codes and there budgets for the entire year.
I have grouped the multiple projects under Labs. So I want to filter the project codes in the pivot which in turn effects an Chart.
I tried to use macro recording but it returns a Macro with lot of lines pivot item ac039 = false and finally gives an error that the procedure is too large.
I got the below macro. But this un-ticks the project codes one by one and each time the entire report refreshes and the slicers run taking several hours.
I tried using manual update = true but i dont know whether it is kicking in or not. All i need is remove all filters and keep the project codes which I need to have. The project codes may vary from 1 to 10 project codes at a time.
<code style="margin: 0px;">ption Explicit
Sub FilterPivotItems()
Dim PT As PivotTable
Dim PTItm As PivotItem
Dim FiterArr()AsVariant
' use an array to select the items in the pivot filter you want to keep visible
FiterArr = Array("101","105","107")
' set the Pivot Table
Set PT = ActiveSheet.PivotTables("PivotTable3")
' loop through all Pivot Items in "Value" Pivot field
ForEach PTItm In PT.PivotFields("Value").PivotItems
IfNot IsError(Application.Match(PTItm.Caption, FiterArr,0))Then' check if current item is not in the filter array
PTItm.Visible =True
Else
PTItm.Visible =False
EndIf
Next PTItm
EndSub</code>