Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 927
  • Last Modified:

Excel 2007 Pivot Table Filter Based On Dynamic Cell

Hello Experts - Please see attached file.  I'd like to know if there is a way to based multiple pivot table filter selections on a specific cell.  Based on the attached sample file, if someone was to chose a different month in cell M2 on the first tab, all of the filters in the 3 pivot tables would change to that new month.

Thanks!!!
EE-Sample-File.xlsm
0
Escanaba
Asked:
Escanaba
1 Solution
 
Rory ArchibaldCommented:
Right-click the worksheet tab, choose View Code then paste this in:
Private Sub Worksheet_Change(ByVal Target As Range)
   Dim pt As PivotTable
   Dim pf As PivotField
   On Error GoTo err_handle

   With Application
      .ScreenUpdating = False
      .EnableEvents = False
   End With
   If Not Intersect(Target, Me.Range("M2")) Is Nothing Then
      For Each pt In Me.PivotTables
         pt.ManualUpdate = True
         Set pf = pt.RowFields(1)
         pf.ClearAllFilters
         pf.PivotFilters.Add Type:=xlCaptionEquals, Value1:=Range("M2").Value
         pt.ManualUpdate = False
      Next pt
   End If
clean_up:
   With Application
      .EnableEvents = True
      .ScreenUpdating = True
   End With
   Exit Sub

err_handle:
   MsgBox Err.Description
   Resume clean_up
End Sub

Open in new window

0
 
EscanabaAuthor Commented:
As always, thank you for your quick and accurate response.
0

Featured Post

Ask an Anonymous Question!

Don't feel intimidated by what you don't know. Ask your question anonymously. It's easy! Learn more and upgrade.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now