Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

The Power BI DataViz World Championships are on! With four chances to enter, you could win a spot in the LIVE Grand Finale in Las Vegas. Show off your skills.

Reply
Freewilly3d
New Member

Analyze in Excel pivottable; vba set filters; Col filters work except on 1 column error 1004

I have a parameter file below to set filters and a subroutine to read the parameters and set the filters in a pivottable. The filters for the first 2 columns (lines 2 [Environment] and 3 [ENT_PERIOD_END_DT]) work as expected, values get set. The third column (row 4) does not. The most puzzling part is the code runs the statement pf.ClearAllFilters then aborts with a 1004 the item could not be found in the Olap Cube on the line with the statement pf.CurrentPageName = FilterVal. I recorded a manual change to this filter and that code fails with the same error. Manually setting the filter on the sheet works fine. Is it possible there is something in the Powerpivot model that is preventing this filter from being changed in VBA. Any suggestions?

 

Parameters

Worksheet,Filter,Value,Type
Occupancy (Monthly),[Environment].[Environment].[Environment],[Environment].[Environment].&[QAGDW],string
Occupancy (Monthly),[Dim_Calendar_D].[ENT_PERIOD_END_DT].[ENT_PERIOD_END_DT],[Dim_Calendar_D].[ENT_PERIOD_END_DT].&[2016-03-31T00:00:00],date
Occupancy (Monthly),[Supp_Portfolio_D].[SUPPLEMENTAL_PORTFOLIO_NAME].[SUPPLEMENTAL_PORTFOLIO_NAME],[Supp_Portfolio_D].[SUPPLEMENTAL_PORTFOLIO_NAME].&[Operations],string

And This sub-routine

Sub SetPivotFilters()
Dim FilterCol As String
Dim FilterVal As String
myWorksheetpath = ThisWorkbook.Path
myParmFileName = Split(ThisWorkbook.Name, ".")(0) & "_parms.csv"
Open ThisWorkbook.Path & "\" & myParmFileName For Input As #1
row_number = 0
'Application.EnableEvents = False
ActiveSheet.PivotTables("PivotTable3").PivotCache.Refresh
Do Until EOF(1)
Line Input #1, LineFromFile
LineItems = Split(LineFromFile, ",")
FilterCol = LineItems(1)
FilterVal = LineItems(2)

'skip heading line in parm file
If row_number > 0 Then
Dim pf As PivotField
For Each pvt In ActiveSheet.PivotTables
myname = pvt.Name
'pvt.ManualUpdate = True
Set pf = pvt.PivotFields(FilterCol)
pf.ClearAllFilters
pf.CurrentPageName = FilterVal
Next
End If
2 REPLIES 2
GM1
Frequent Visitor

We have the same issue... Was there ever a resolution for this ?

Anonymous
Not applicable

I was able to make it work by replacing the CurrentPage to CurrentPageName in the recorded macro.

Helpful resources

Announcements
Feb2025 Sticker Challenge

Join our Community Sticker Challenge 2025

If you love stickers, then you will definitely want to check out our Community Sticker Challenge!

Jan NL Carousel

Fabric Community Update - January 2025

Find out what's new and trending in the Fabric community.