Quantcast
Channel: Developer topics
Viewing all articles
Browse latest Browse all 18030

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

$
0
0

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

Viewing all articles
Browse latest Browse all 18030

Trending Articles