Unable to get the PivotFields property of the PivotTable class

Opal

New Member
Joined
May 1, 2005
Messages
17
I have been struggling to get this to work for a couple of days now. I have been reading posts but nothing seems to solve the issue I am having so I am hoping someone out there can see what I cannot see. I am using Excel 2016 and working with multiple pivot tables. What I want to do is that when the value changes in a cell outside of the Pivot Table I want the filter on the column to update with the new value. So basically I have source data for three pivot tables on one worksheet tab. From there I calculate the top 3 injured body part from this data and then each pivot table is to filter with the Top1, 2 , 3 showing the area in the shop and the work process that the employee was on where the injury occurred. However, when I attempted to refresh the data I get the error: Unable to get the PivotFields property of the PivotTable class

Here is my code for one of the Pivot Tables:
Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)

'This line stops the worksheet updating on every change, 'it only updates when cell'B4
'or B5 is touched

If Intersect(Target, Range("B1:C1")) Is Nothing Then Exit Sub

'Set the Variables to be used
Dim pt1 As PivotTable
Dim FieldInjuryTop1 As PivotField
Dim NewInjuryTop1 As String

'Amend here to filter your data
Set pt1 = Worksheets("Pivot Table Top1").PivotTables("PivotTable1")
Set FieldInjuryTop1 = pt1.PivotFields("Count of Injury Map Body Part")
NewInjuryTop1 = Worksheets("Weekly TIR Summary Data").Range("TopN1").Value

'This updates and refreshes the PIVOT table
With pt1
FieldInjuryTop1 = NewInjuryTop1
FieldInjuryTop1.CurrentPage = NewInjuryTop1
pt1.RefreshTable
End With

End Sub

This line: Set FieldInjuryTop1 = pt1.PivotFields("Count of Injury Map Body Part")

is what causes the error. Any assistance, links, advice you can provide would be appreciated. Thank you.
 
Last edited by a moderator:
So I re-created the file again and when I try the aTest() above I get:

$B$6:$R$133

In the immediate Window.

... and when I run my code, above, I get "Method 'CurrentPage' of object 'PivotField' failed

Pointing to this line: FieldInjuryTop1.CurrentPage = NewInjuryTop1

If I reset everything and try again, I get the same Unable to get the DataFields property of the PivotTable class error for both my code and the aTest.... sigh
 
Upvote 0

Excel Facts

Quick Sum
Select a range of cells. The total appears in bottom right of Excel screen. Right-click total to add Max, Min, Count, Average.

Forum statistics

Threads
1,224,802
Messages
6,181,054
Members
453,014
Latest member
Chris258

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