HI,
I am trying to to change the the filter on a Pivot Table use the below VBA. I think the issue is with connecting to an Olap cube pivot table and not a normal pivot table. Highlighted in red is where the debug throws the error:
"Run-time error '1004':
Unable to set the CurrentPage property of the PivotField Class"
Any help would be appreciated
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Intersect(Target, Range("C6:C7")) Is Nothing Then Exit Sub
Dim pt As PivotTable
Dim Field As PivotField
Dim SalesChannel As String
Dim Fields As PivotFields
Dim Name As String
Dim setValue As String
Set pt = Worksheets("Data").PivotTables("PivotTable1")
Set Fields = pt.PivotFields
For Each Field In Fields
Name = Field.Name
If Name = "[Sales Channel].[Sales Channel].[Sales Channel]" Then
Exit For
End If
Next
setValue = Worksheets("Tool").Range("C6").Value
With Field
.ClearAllFilters
.CurrentPage = setValue
End With
pt.RefreshTable
End Sub
I am trying to to change the the filter on a Pivot Table use the below VBA. I think the issue is with connecting to an Olap cube pivot table and not a normal pivot table. Highlighted in red is where the debug throws the error:
"Run-time error '1004':
Unable to set the CurrentPage property of the PivotField Class"
Any help would be appreciated
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Intersect(Target, Range("C6:C7")) Is Nothing Then Exit Sub
Dim pt As PivotTable
Dim Field As PivotField
Dim SalesChannel As String
Dim Fields As PivotFields
Dim Name As String
Dim setValue As String
Set pt = Worksheets("Data").PivotTables("PivotTable1")
Set Fields = pt.PivotFields
For Each Field In Fields
Name = Field.Name
If Name = "[Sales Channel].[Sales Channel].[Sales Channel]" Then
Exit For
End If
Next
setValue = Worksheets("Tool").Range("C6").Value
With Field
.ClearAllFilters
.CurrentPage = setValue
End With
pt.RefreshTable
End Sub