Need macro to change filter in pivot table based off a cell value

Some videos you may like

Excel Facts

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.

Worf

Well-known Member
Joined
Oct 30, 2011
Messages
4,010
An example:

Code:
Sub PTFilter()
Dim pt As PivotTable, pf As PivotField, i%
Set pt = ActiveSheet.PivotTables("pivottable1")
Set pf = pt.PivotFields("sales person")
pf.ClearAllFilters

' compare with cell D10

For i = 1 To pf.PivotItems.Count
    If pf.PivotItems(i).Name <> [d10] Then pf.PivotItems(i).Visible = 0
Next
End Sub
 
Last edited:

Watch MrExcel Video

Forum statistics

Threads
1,109,001
Messages
5,526,203
Members
409,686
Latest member
Tori83

This Week's Hot Topics

Top