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:
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.
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: