Runtime Error 1004: Unable to get pivotfields property of the PivotTable Class

atoice

New Member
Joined
Aug 14, 2019
Messages
9
Office Version
  1. 2013
Platform
  1. Windows
Hello Community,

Looking for a little VBA love. Current macro simply done by recording. So I couldn't screw up the language code.

I have 2 sheets: 1 for Brands and Brands Top Gain Loss. I would like to get rid of one sheet and allow a macro for Sort by "Dollar Sales" and "Dollar Sales Chg YA". And then filter to the Top 20 or Bottom 20.

Sub Top20Rank()


' Top20Rank Macro


Range("D8").Select
ActiveSheet.PivotTables("PivotTable1").PivotFields("Brands").AutoSort _
xlDescending, "Dollar Sales Chg YA", ActiveSheet.PivotTables("PivotTable1"). _
PivotColumnAxis.PivotLines(3), 1

Range("A8").Select
ActiveSheet.PivotTables("PivotTable1").PivotFields("Brand Value").PivotFilters. _
Add2 Type:=xlTopCount, DataField:=ActiveSheet.PivotTables("PivotTable1"). _
PivotFields("Dollar Sales Chg YA"), Value1:=20

End Sub



I get the Error 1004. Any chance you can help with the error?

Thank you as always in advance.
 

Excel Facts

Select all contiguous cells
Pressing Ctrl+* (asterisk) will select the "current region" - all contiguous cells in all directions.

Forum statistics

Threads
1,223,893
Messages
6,175,246
Members
452,623
Latest member
cliftonhandyman

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