Filter Excel pivot table using VBA

后端 未结 6 2198
温柔的废话
温柔的废话 2020-12-03 17:40

I have tried copying and pasting solutions from the internet forever now to try to filter a pivot table in Excel using VBA. The code below doesn\'t work.

Sub         


        
6条回答
  •  一整个雨季
    2020-12-03 18:35

    In Excel 2007 onwards, you can use the much simpler code using a more precise reference:

    dim pvt as PivotTable
    dim pvtField as PivotField
    
    set pvt = ActiveSheet.PivotTables("PivotTable2")
    set pvtField = pvt.PivotFields("SavedFamilyCode")
    
    pvtField.PivotFilters.Add xlCaptionEquals, Value1:= "K123223"
    

提交回复
热议问题