VBA - Change value of Top10 filter in existing pivotTable

thomas819

New Member
Joined
Nov 23, 2020
Messages
36
Office Version
  1. 2019
Platform
  1. Windows
Hello all,
I would like to ask you all, if you can help me with this seamingly simple task.... I need to change Value1 in a dynamic way. Value1:= Range("C1").Value
VBA Code:
Sub Top10filter()

    ActiveSheet.PivotTables("TOP").PivotFields( _
        "[summary].[Full_name].[Full_name]").PivotFilters.Add2 Type:=xlTopCount, _
        DataField:=ActiveSheet.PivotTables("TOP").CubeFields( _
        "[Measures].[Total sum of holiday]"), Value1:=12
End Sub

When I run this recorded macro, I always got:
Run-time error '1004':
Application-defined or object-defined error

I am in lost... Could anybody tell me how should I correctly define this existing pivotTable in order to apply dynamic change of Value1?
 

Excel Facts

How to create a cell-sized chart?
Tiny charts, called Sparklines, were added to Excel 2010. Look for Sparklines on the Insert tab.
Solution was surprisingly straight forward
VBA Code:
Sub Top10filter()

    ActiveSheet.PivotTables("Top").PivotFields("[summry].[Full_name].[Full_name]").ClearAllFilters
    ActiveSheet.PivotTables("TOP").PivotFields( _
        "[summary].[Full_name].[Full_name]").PivotFilters.Add2 Type:=xlTopCount, _
        DataField:=ActiveSheet.PivotTables("TOP").CubeFields( _
        "[Measures].[Total sum of holiday]"), Value1:=Range("C1").Value
End Sub

I just need add ClearAllFilters clause
 
Upvote 0
Solution

Forum statistics

Threads
1,214,972
Messages
6,122,530
Members
449,088
Latest member
RandomExceller01

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