View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Hong Quach Hong Quach is offline
external usenet poster
 
Posts: 21
Default Pivot Page field filter based on cell value

Hi Michel,

You can try the code below.

Dim pt As PivotTable
ActiveSheet.Select
For Each pt In ThisWorkbook.ActiveSheet.PivotTables
pt.PageFields("FIELD_NAME").dataRange = "CHOSEN_VALUE"
Next

You can filter multiple things in this For-Loop. You can also add If Else
statements to check for pt.name to apply extra filter to certain pt in the
sheet.

Note that I didn't have any error checking in here because you didn't ask
for, but as long as you are not asking the macro to filter the pt to
something that is not on the list then you are fine.

Hong Quach

" wrote:

Hi, I am new in VBA and I have created a code that gets information
from an access query and set up a pivot table. The worksheet contains
multiple pivottables. All pivot tables have at least one page field
(product). The worksheet should be copied and then every pivot on the
active sheet should be filtered on one product (example: worksheet for
milk, worksheet for cheese, worksheet for etc). This for every product
(couple op 30-35 products).

How can I copy the 'mastersheet' (named ' Master') and filter all
pivot tables for a specific Page field product? May be copy worksheet
and set cell a1 to a specific value?