Filtering OLAP Pivot Table by array

krogh101

New Member
Joined
Jun 29, 2015
Messages
19
Hi all,

I am trying to filter a Pivot Table that has a OLAP source, by multiple ItemId's in the worksheet.

The values that I want to filter by is in cell A2 and down. The list of ItemId's that should be visible in the Pivot Table could be anything from 1 to 500

As a small test i wrote the following line of code, and it works great.

Code:
input_SH.PivotTables("PT_INPUT").PivotFields("[Item].[ItemID].[ItemID]").VisibleItemsList = Array("[Item].[ItemID].&[1133339]", "[Item].[ItemID].&[1133340]")

However, when using a variable (ITEMID) I only get a Run-time Error '1004'.

Code:
Sub UpdateItemPT()

        Dim ITEMID As Variant
        Dim i As Integer
        
        
        ITEMID = ""
        For i = 2 To input_SH.Range("A2").End(xlDown).Row
            
            If i = 2 Then
                ITEMID = """" & "[Item].[ItemID].[ItemID].&[" & input_SH.Cells(i, 1).Value & "]"""
            Else
                ITEMID = ITEMID & ",""" & "[Item].[ItemID].[ItemID].&[" & input_SH.Cells(i, 1).Value & "]"""
            End If
            
        Next
             
'ITEMID is now: "[Item].[ItemID].&[1133339]", "[Item].[ItemID].&[1133340]"
    
input_SH.PivotTables("PT_INPUT").PivotFields("[Item].[ItemID].[ItemID]").VisibleItemsList = Array(ITEMID)

End Sub

Any help would be appreciated!
 

Excel Facts

Wildcard in VLOOKUP
Use =VLOOKUP("Apple*" to find apple, Apple, or applesauce

Forum statistics

Threads
1,223,911
Messages
6,175,324
Members
452,635
Latest member
laura12345

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