First of all, thanks a lot for the initial answer. This already helped me a great deal in the past.
I couldn't work with slicers as I had to group one of the dimensions in a few different ways, so I was forced to create a new data source connection for every Pivot Table.
Unfortunately I have run into an issue now.
Part of the dimensions in the OLAP cube I am using are a layered hierarchy, for example:
Code:
L1: "[Items].[Product Hierarchy].[Business Group]"
L2: "[Items].[Product Hierarchy].[Retail Department]"
L3: "[Items].[Product Hierarchy].[Retail Group]"
L4: "[Items].[Product Hierarchy].[Item]"
When I record a macro and set this filter to a certain value, it seems to set each of these levels individually.
In the example below I only selected something on the first level, which is why it shows an empty array on the lower levels.
Code:
ActiveSheet.PivotTables("BELGIUM_RT_DATE_PROCOM").PivotFields( _
"[Items].[Product Hierarchy].[Business Group]").VisibleItemsList = Array( _
"[Items].[Product Hierarchy].[Business Group].&[Beauty Make-Up]")
ActiveSheet.PivotTables("BELGIUM_RT_DATE_PROCOM").PivotFields( _
"[Items].[Product Hierarchy].[Retail Department]").VisibleItemsList = Array("")
ActiveSheet.PivotTables("BELGIUM_RT_DATE_PROCOM").PivotFields( _
"[Items].[Product Hierarchy].[Retail Group]").VisibleItemsList = Array("")
ActiveSheet.PivotTables("BELGIUM_RT_DATE_PROCOM").PivotFields( _
"[Items].[Product Hierarchy].[Item]").VisibleItemsList = Array("")
However when I try to use your code to sequentially set each of the levels, the code runs without an error, but it didn't actual change the report filter of the destination pivot.
I tried the same on a dimension that isn't layered using the same Pivot Tables and that worked like a charm.
Code:
Dim pvtSource As PivotTable, pvtDest As PivotTable
Const sFIELDNAME1 As String = "[Items].[Product Hierarchy].[Business Group]"
Const sFIELDNAME2 As String = "[Items].[Product Hierarchy].[Retail Department]"
Const sFIELDNAME3 As String = "[Items].[Product Hierarchy].[Retail Group]"
Const sFIELDNAME4 As String = "[Items].[Product Hierarchy].[Item]"
Const sFIELDNAME5 As String = "[Items].[Business Group].[Business Group]"
Set pvtSource = Slicer.PivotTables("FAKE_SLICER")
Set pvtDest = TEST.PivotTables("TEST")
'Trying to set the layered dimension:
pvtDest.PivotFields(sFIELDNAME1).VisibleItemsList = _
pvtSource.PivotFields(sFIELDNAME1).VisibleItemsList
pvtDest.PivotFields(sFIELDNAME2).VisibleItemsList = _
pvtSource.PivotFields(sFIELDNAME2).VisibleItemsList
pvtDest.PivotFields(sFIELDNAME3).VisibleItemsList = _
pvtSource.PivotFields(sFIELDNAME3).VisibleItemsList
pvtDest.PivotFields(sFIELDNAME4).VisibleItemsList = _
pvtSource.PivotFields(sFIELDNAME4).VisibleItemsList
'Setting a dimension that isn't layered:
pvtDest.PivotFields(sFIELDNAME5).VisibleItemsList = _
pvtSource.PivotFields(sFIELDNAME5).VisibleItemsList
End Sub
Is this something that just isn't supported in Excel 2013? Or am I doing something wrong?
I'm using Excel 2010 in case that would be relevant.
Thanks in advance to anyone trying to figure this out.
PS.
The fact I changed the code from using the ActiveSheet to VBA sheet names isn't the problem, as setting the non-layered dimension in the same sub worked.