Bulk filtering a pivot using VBA

broncosrul

New Member
Joined
May 3, 2012
Messages
25
I am looking for a way to "upload" a list of selections for a filter on a pivot table. The pivot is connected to an OLAP cube, so there are tens of thousands of records and we often only need to look at a small selection. However, finding those in the pivot is difficult without adding them one by one. So, I was able to use this bit of VBA to run a macro to do the filtering.

Code:
[TABLE="width: 374"]
<tbody>[TR]
[TD]Sheets("Pivot").Select
[/TD]
[/TR]
[TR]
[TD]ActiveSheet.PivotTables("PivotTable1").PivotFields( _
[/TD]
[/TR]
[TR]
[TD]"[Product].[ItemIDs].[ItemID]").VisibleItemsList = Array( _
[/TD]
[/TR]
[TR]
[TD]"[Product].[ItemIDs].[ItemID].&[TFP_200090]", _
[/TD]
[/TR]
[TR]
[TD]"[Product].[ItemIDs].[ItemID].&[TFP_200091]", _
[/TD]
[/TR]
[TR]
[TD]"[Product].[ItemIDs].[ItemID].&[TFP_200092]", _
[/TD]
[/TR]
[TR]
[TD]"[Product].[ItemIDs].[ItemID].&[TFP_200093]", _
[/TD]
[/TR]
[TR]
[TD]"[Product].[ItemIDs].[ItemID].&[TFP_200094]", _
[/TD]
[/TR]
[TR]
[TD]"[Product].[ItemIDs].[ItemID].&[TFP_200095]", _
[/TD]
[/TR]
[TR]
[TD]"[Product].[ItemIDs].[ItemID].&[TFP_200096]", _
[/TD]
[/TR]
[TR]
[TD]"[Product].[ItemIDs].[ItemID].&[TFP_200333]", _
[/TD]
[/TR]
[TR]
[TD]"[Product].[ItemIDs].[ItemID].&[TFP_200337]")
[/TD]
[/TR]
</tbody>[/TABLE]

As you can see, it is a really long line of code that is connected with line continuations. However, VBA limits continuations at 24 and we would often want more records than that. I realize I can make one ridiculously long line by eliminating the continuations, but besides being unreadable, it seems like there would be a better option. Is there some bit of code that would be more efficient that would work on a pivot table? Something like an IN statement seems like it would be the best option.

Thanks
 

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.
Is there code that would let me just make each item visible using a TRUE statement rather than using the array? (and still keep the preceding ones as part of the filter). The Array is what is causing me to have the long line of code.
 
Upvote 0

Forum statistics

Threads
1,223,903
Messages
6,175,284
Members
452,630
Latest member
OdubiYouth

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