Using VBA to update pivot table filter from multiple values

Tyler0320

New Member
Joined
Apr 4, 2018
Messages
3
I am looking to create a VBA macro that has the ability to update one pivot table filter based on multiple cell values. I have successfully been able to create VBA code to update the pivot table filter with ONE value but would like to modify this code to update the filter with MULTIPLE values.

Below is the code where I have successfully been able to update with ONE value:

Sub TEST()
'
' TEST Macro
'

Dim pt As PivotTable
Dim Field As PivotField
Dim NewCat As String

Set pt = Worksheets("CATALOG_DATABASE").PivotTables("PivotTable2")
Set Field = pt.PivotFields("Item #")
NewCat = Worksheets("INVOICE").Range("U18").Value

With pt
Field.ClearAllFilters
Field.CurrentPage = NewCat
pt.RefreshTable
End With

End Sub

My range of values that I would like to pull from is on Worksheet("INVOICE"), Range(S1:S15). Although this range goes down 15 rows, not all rows may have a value (case by case basis depending on invoice).

I am pretty new to writing VBA code but am looking for any help to achieve this goal.

Thank you,
Tyler
 

Excel Facts

Bring active cell back into view
Start at A1 and select to A9999 while writing a formula, you can't see A1 anymore. Press Ctrl+Backspace to bring active cell into view.
Apologies for not using code tags in my original post. Below is the code with the tags

Code:
Sub TEST()
'
' TEST Macro
'
 
Dim pt As PivotTable
Dim Field As PivotField
Dim NewCat As String
 
Set pt = Worksheets("CATALOG_DATABASE").PivotTables("PivotTable2")
Set Field = pt.PivotFields("Item #")
NewCat = Worksheets("INVOICE").Range("U18").Value
 
With pt
Field.ClearAllFilters
Field.CurrentPage = NewCat
pt.RefreshTable
End With

End Sub
 
Upvote 0

Forum statistics

Threads
1,223,903
Messages
6,175,286
Members
452,631
Latest member
a_potato

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