3

Using VBA code, I have created a Pivot table and then added row, columns and then the summation values. Now I need to add a filter on a column. Can you please let me know how can I add filters to this column.

Pᴇʜ
  • 56,719
  • 10
  • 49
  • 73
meru
  • 47
  • 1
  • 5
  • Did you try some code? Can you post it? Did you do research on the topic? What did you search for? What did you find? –  May 05 '17 at 06:44
  • No I couldnt find any reference. Foe adding Row, Column and Summation I had used as below. But nothing for FILTER. – meru May 05 '17 at 07:18
  • Set pvtFld = PvtTbl.PivotFields("Order\ Amendment Approval Stage") pvtFld.Orientation = xlRowField pvtFld.Position = 5 Set pvtFld = PvtTbl.PivotFields("SOWPODateQtr") pvtFld.Orientation = xlColumnField pvtFld.Position = 1 Set pvtFld = PvtTbl.PivotFields("SERVICE ACV IN $ PLANNED") pvtFld.Orientation = xlDataField pvtFld.Position = 1 pvtFld.Function = xlSum pvtFld.NumberFormat = "#,##0" – meru May 05 '17 at 07:18
  • What exactly do you need a reference for? How to [apply filter to pivot table with VBA in Excel](https://www.google.at/search?q=Apply+filter+to+pivot+table+with+VBA+in+Excel&oq=Apply+filter+to+pivot+table+with+VBA+in+Excel&aqs=chrome..69i57j0.535j0j7&sourceid=chrome&ie=UTF-8)? –  May 05 '17 at 07:53
  • While creating a Pivot table manullay, we have the options to enter row fields, column fields, sum fields and then Filter fields. How do i replicate the 'Filter fields" options using VBA ? – meru May 05 '17 at 08:22
  • A quick [search](https://www.google.at/search?safe=off&q=vba+excel+apply+filter+pivot+table&spell=1&sa=X&ved=0ahUKEwjHho_6rNjTAhXMORQKHUqRAuoQvwUIJCgA&biw=1536&bih=760) returns lots of useful examples you can try out. Try the code in [this](http://stackoverflow.com/questions/11071662/filter-excel-pivot-table-using-vba) SO post and edit your question if you get stuck on a specific problem/line –  May 05 '17 at 08:41

2 Answers2

2

Try the following code:

Sub Makró2()
    With ActiveSheet.PivotTables("Kimutatás1").PivotFields("a")
        .PivotItems("asd").Visible = False
        .PivotItems("hj").Visible = False
    End With
End Sub

For example:

enter image description here

Zsmaster
  • 1,549
  • 4
  • 19
  • 28
  • Is it not easy as adding a row/Column syntax to a pivot. Somehting like this > – meru May 05 '17 at 07:17
  • Set pvtFld = PvtTbl.PivotFields("Account") pvtFld.Orientation = xlRowField pvtFld.Position = 1 – meru May 05 '17 at 07:17
0

Try below line of codes

With ActiveSheet.PivotTables("PivotTable Name").PivotFields("Column Name").Orientation = xlPageField.Position = 1