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:

Some videos you may like

Excel Facts

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.

Watch MrExcel Video

Forum statistics

Threads
1,118,746
Messages
5,573,986
Members
412,562
Latest member
woodportaj
Top