Good evening,
Not a VBA expert at all so finally reached a point where I am stuck. I have a data source with inventory information that is already set up in a pivot table. I have a list of 190 reference numbers that each need there own version of the original pivot table and on their own individual sheet. I was able to put together a couple of simple macros that did the sheet creation and naming, but all the filtering had to be done manually. I would love to be able to figure out how to run a macro that would automate the filtering across the workbook based on a specific cell value on each page that I have linked to the original list. I tried a few different codes I found online and found one that would change the filter on a specific sheet/pivot table and when I combined it with another, I was able to get it to populate across multiple sheets, but it applied the same value to the filter across the sheets instead of reading the cell on each sheet. In experimenting, I lost that code and couldn't remember what I did so this is the current code that I have now:
Not a VBA expert at all so finally reached a point where I am stuck. I have a data source with inventory information that is already set up in a pivot table. I have a list of 190 reference numbers that each need there own version of the original pivot table and on their own individual sheet. I was able to put together a couple of simple macros that did the sheet creation and naming, but all the filtering had to be done manually. I would love to be able to figure out how to run a macro that would automate the filtering across the workbook based on a specific cell value on each page that I have linked to the original list. I tried a few different codes I found online and found one that would change the filter on a specific sheet/pivot table and when I combined it with another, I was able to get it to populate across multiple sheets, but it applied the same value to the filter across the sheets instead of reading the cell on each sheet. In experimenting, I lost that code and couldn't remember what I did so this is the current code that I have now:
VBA Code:
Sub ChangePivotFilter()
Dim WS As Excel.Worksheet
Dim aWB As Excel.Workbook
Dim myPivot As Excel.PivotTable
Dim myPivotField As Excel.PivotField
Dim strFilter As String
Set aWB = ActiveWorkbook
For Each WS In aWB.Worksheets
For Each myPivot In WS.PivotTables
Set myPivotField = Nothing
On Error Resume Next
Set myPivotField = myPivot.PivotFields("FACILITY_CODE")
myPivotField = aWB.ActiveSheet.Range("C1").Value
Next
myPivot
Next
WS
End Sub