Can I use a Loop to change the filters in a Pivot Table from Power Pivot?

bigck2

Board Regular
Joined
Feb 20, 2014
Messages
147
Hello,

I am trying to use a VBA loop to adjust the filters on a Pivot Table built with Power Pivot to make and print a report for each business unit.

I have been trying to use the Macro recorder but I get an error message saying "Unable to set the CurrentPage property of the PivotField Class"


Here is the code I am using (again this mainly just modified from the Macro recorder):

Code:
Sub PropertiesLoop()




    Worksheets("Properties").Activate
    
    Dim LR As Long
    Dim PropertyName As String
    
    
    LR = Cells(Rows.Count, 1).End(xlUp).Row
    
    For i = 2 To LR
    
        PropertyName = Cells(i, 1).Value
        
        Worksheets("Revenue PT").Activate
        
        
        ActiveSheet.PivotTables("SS Revenue").PivotFields( _
        "[SameStores].[Project  Name].[Project  Name]").ClearAllFilters
        
        ActiveSheet.PivotTables("SS Revenue").PivotFields( _
        "[SameStores].[Project  Name].[Project  Name]").CurrentPage = _
        "[SameStores].[Project  Name].&[" & PropertyName & "]"
            
        
    Next i

End Sub


Please let me know if what I am wanting to do is possible?

Thanks,

Chris
 

Excel Facts

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.
Hey Scottsen,

I'll have to look at your other thread in more detail.

In case anyone else reads this I just wanted to say that I had much better results using slicers than filters. Not sure why, but I was able to accomplish what I needed using some variation of this code:


Code:
     Sheets("Rev SS PT").Select
        
                    ActiveWorkbook.SlicerCaches("Slicer_Project__Name1").ClearAllFilters
                    ActiveWorkbook.SlicerCaches("Slicer_Project__Name1").VisibleSlicerItemsList = _
                    Array( _
                    "[SameStores].[Project  Name].&[" & PropertyName & "]")


                    Range("A1").Value = PropertyName
 
Upvote 0

Forum statistics

Threads
1,224,065
Messages
6,176,169
Members
452,710
Latest member
mrmatt36

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