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

VBA code to change pivot filter not working

MissLady11

New Member
In this file there is a tab called BSS. On this tab I have code that I am using to Update a pivot filter based on the name that's in cell x7.

It's the second part of the code. The first part updated the data under that chart so it's good.

The second part is what I can't figure out.

In my code on this tab, where you see:
'This line stops the worksheet updating on every change, it only updates when cell
'x7 is touched

Everything under this is what I am trying to get to work for the pivot.
Basically I'm trying to write code to say based on the name you see in cell x7, change the pivot filter (Resource Pool Name) to that name




Disregard the errors in the chart on this tab...I had to break the pivot to send the file...
 

Attachments

  • Update Pivot VBA Code.xlsm
    742.8 KB · Views: 3
Figured out the code...this is what I put in place of what I had:
'This line stops the worksheet updating on every change, it only updates when cell
'x7 is touched
'Set the Variables to be used
Dim pt As PivotTable
Dim Field As PivotField
Dim NewCat As String

'Here you amend to suit your data
Set pt = Worksheets("BSS").PivotTables("BSSDmd")
Set Field = pt.PivotFields("Resource Pool Name")
NewCat = Worksheets("BSS").Range("x7").Value

If NewCat = "" Then
Exit Sub
End If
 
Back
Top