Filter Excel pivot table using VBA

后端 未结 6 2206
温柔的废话
温柔的废话 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:44

    Latest versions of Excel has a new tool called Slicers. Using slicers in VBA is actually more reliable that .CurrentPage (there have been reports of bugs while looping through numerous filter options). Here is a simple example of how you can select a slicer item (remember to deselect all the non-relevant slicer values):

    Sub Step_Thru_SlicerItems2()
    Dim slItem As SlicerItem
    Dim i As Long
    Dim searchName as string
    
    Application.ScreenUpdating = False
    searchName="Value1"
    
        For Each slItem In .VisibleSlicerItems
            If slItem.Name <> .SlicerItems(1).Name Then _
                slItem.Selected = False
            Else
                slItem.Selected = True
            End if
        Next slItem
    End Sub
    

    There are also services like SmartKato that would help you out with setting up your dashboards or reports and/or fix your code.

提交回复
热议问题