VBA to filter a pivot table

Pranesh

Board Regular
Joined
Jun 29, 2014
Messages
219
Hi All,

I have a list of names available in Cell D1. At times names will be starting with <> and at few scenarios before names there wont be "<>".

If i have this <> symbol at the starting of the name which means i need to exclude the names from a pivot item in a pivot table.

If i have only names then it means i need to include only those name from a pivot item in a pivot table

example for excluding names - <>John, Dave, Smith(will be available in Cell D1)

example for including names - John, Dave, Smith(will be available in cell D1)

Currently im doing this manually and i would like to automat it. Can someone help me with the code.
 

Excel Facts

Spell Check in Excel
Press F7 to start spell check in Excel. Be careful, by default, Excel does not check Capitalized Werds (whoops)
Hi All,

I have managed to record a code and modified it. This will work for one item(Smith) in cell I2, but if i have 2 items in cell I2 (Smith, Dave) it wont work.


Can someone help me to modify this code to convert cell I2 as array and all names in cell I2 should be filtered in Pivot.

Code:
Range("H2").Select
    Findstring = Selection.Value
    Range("I2").Select
    Findstring1 = Selection.Value
    
    ActiveSheet.PivotTables("PivotTable1").PivotFields("track").ClearAllFilters
    If Findstring = "<>" Then
    With ActiveSheet.PivotTables("PivotTable1").PivotFields("track")
        .PivotItems(Findstring1).Visible = False
    End With
    Else
    With ActiveSheet.PivotTables("PivotTable1").PivotFields("track")
        .PivotItems(Findstring1).Visible = True
    End With
    End If
 
Last edited:
Upvote 0

Forum statistics

Threads
1,224,837
Messages
6,181,255
Members
453,028
Latest member
letswriteafairytale

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