Run-time error '1004' Unable to get PivotFields property of the PivotTable class in Excel 2013

Bmort

New Member
Joined
Sep 23, 2020
Messages
7
Office Version
  1. 365
  2. 2013
Platform
  1. Windows
I am receiving this error:
Run-time error '1004' Unable to get PivotFields property of the PivotTable class
This is occurring for me in Excel VBA (version 2013), but the same code executes successfully on a different machine running Office 365.
Code:
With pt
  .PivotFields(fieldName).ClearLabelFilters
  .PivotFields(fieldName).PivotFilters.Add Type:=xlCaptionEquals, Value1:=strFilter
End With
In order to ensure I was naming the pivot fields correctly, I tried looping through the pivot table to get the names of all the pivot tables and fields:
Dim pt As PivotTable
Dim pf As PivotField

wb.Worksheets("Sheet1").Activate
For Each pt In wb.Worksheets("Sheet1").PivotTables
  Debug.Print pt.Name
  For Each pf In pt.PivotFields
    Debug.Print pf.Name
  Next pf
Next pt
This successfully prints the name of the pivot table, but gives the same error when it hits this line:
Code:
For Each pf In pt.PivotFields
I tried by recording a macro and changing a filter in the PivotTable. The recorded macro fails on the following line:
Code:
ActiveSheet.PivotTables("testPivotTable").PivotFields("TYPE").ClearAllFilters
Please let me know if anyone has insight into why the PivotFields property might be unavailable to my application or any ideas for troubleshooting.
 
Last edited by a moderator:

Excel Facts

Can Excel fill bagel flavors?
You can teach Excel a new custom list. Type the list in cells, File, Options, Advanced, Edit Custom Lists, Import, OK

Forum statistics

Threads
1,223,898
Messages
6,175,272
Members
452,628
Latest member
dd2

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