• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Unable to get the PivotFields property of the Pivot Table Class

Vanessa Maynaes

New Member
Hello,

I am trying to control a pivot table from the dynamic cell value in E2, supervisor name. However, when I run the code below, I get unable to get the PivotFields property of the Pivot Table Class error. At this point, I am unsure what is causing this code. There are no trailing spaces in the field name and as far as I can see there's no error. Please help!


Here's a screenshot of my worksheet. I need A to populate B.
4af72e6c-37c7-4793-afc8-29cefad07a65
upload_2016-8-9_10-23-36.png

Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)

'This line stops the worksheet updating on every change, it only updates when cell
'H6 or H7 is touched
'If Intersect(Target, Range("D1")) Is Nothing Then Exit Sub

'Set the Variables to be used
Dim pt As PivotTable
Dim Field As PivotField
Dim NewSupv As String

'Here you amend to suit your data
Set pt = Worksheets("Report(Mgr)").PivotTables("IncompCourse")
Set Field = pt.PivotFields("Supervisor Name")
NewSupv = Worksheets("Report(Mgr)").Range("E2").Value

'This updates and refreshes the PIVOT table
With pt
Field.ClearAllFilters
Field.CurrentPage = NewSupv
pt.RefreshTable
End With

End Sub
 

Attachments

  • upload_2016-8-9_10-23-31.png
    upload_2016-8-9_10-23-31.png
    73.2 KB · Views: 6
Please upload sample data set.

Hello,

I am trying to control a pivot table from the dynamic cell value in E2, supervisor name. However, when I run the code below, I get unable to get the PivotFields property of the Pivot Table Class error. At this point, I am unsure what is causing this code. There are no trailing spaces in the field name and as far as I can see there's no error. Please help!


Here's a screenshot of my worksheet. I need A to populate B.
4af72e6c-37c7-4793-afc8-29cefad07a65
View attachment 33461

Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)

'This line stops the worksheet updating on every change, it only updates when cell
'H6 or H7 is touched
'If Intersect(Target, Range("D1")) Is Nothing Then Exit Sub

'Set the Variables to be used
Dim pt As PivotTable
Dim Field As PivotField
Dim NewSupv As String

'Here you amend to suit your data
Set pt = Worksheets("Report(Mgr)").PivotTables("IncompCourse")
Set Field = pt.PivotFields("Supervisor Name")
NewSupv = Worksheets("Report(Mgr)").Range("E2").Value

'This updates and refreshes the PIVOT table
With pt
Field.ClearAllFilters
Field.CurrentPage = NewSupv
pt.RefreshTable
End With

End Sub
 
Back
Top