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

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.
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,215,097
Messages
6,123,077
Members
449,094
Latest member
mystic19

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