OLAP pivot table, filtering using VisibleItemsList in VBA

dj4n4

New Member
Joined
Jun 23, 2014
Messages
7
I have an OLAP pivot table. The following code works:

Sub MyCode()
Dim p as PivotTable
Set p = Worksheets("WorksheetName").PivotTables("PivotName")
Set x = p.PivotFields("[COUNTRY].[STATE].[ZIP]")
x.ClearAllFilters
x.CurrentPageName = "[COUNTRY].[STATE].&[12345]"
End Sub


For various reasons I need to use VisibleItemsList instead.

I tried below but I get an application or object defined error message.

What am I doing wrong? I don't understand using vba on these tables much.

Sub MyCode()
Dim p as PivotTable
Set p = Worksheets("WorksheetName").PivotTables("PivotName")
Set x = p.PivotFields("[COUNTRY].[STATE].[ZIP]")
x.ClearAllFilters
x.VisibleItemsList = Array("[COUNTRY].[STATE].&[12345]")
End Sub
 

Excel Facts

Add Bullets to Range
Select range. Press Ctrl+1. On Number tab, choose Custom. Type Alt+7 then space then @ sign (using 7 on numeric keypad)
I think what may have solved it is the following line:

x.cubefield.enablemultipleitems = true

Before I try to assign the visible items list.

By recording a macro, I saw that it was using
Cubefield(205).enablemultipleitems = true

I guess my field is number 205? And x.cubefield seemed to work when I didn't know the number.
 
Upvote 0

Forum statistics

Threads
1,213,510
Messages
6,114,037
Members
448,543
Latest member
MartinLarkin

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