PowerPivot Slicer selection based on cell value using VBA

亡梦爱人 提交于 2019-12-20 06:37:04

问题


I'm having some issues in automating a PowerPivot slicer using vba. What I am trying to do is have the slicer update and only select what is in a certain cell.

So for example assuming the cell was J3 then whatever was typed in J3 that's what would get updated in the slicer.

My values in my slicer are just numbers. The code I currently have (which doesn't work) throws a run time error is below. The formula name of the slicer is "Syndicatenumber" and the cell I would like it to look at and then update is cell J3.

Anythoughts/help would be much appreciated.

Many thanks

 Public Sub Worksheet_Change(ByVal Target As Range)
    Dim SI As SlicerItem
    Application.EnableEvents = False
    If Not Intersect(Target, Range("J3")) Is Nothing Then
        With ActiveWorkbook.SlicerCaches("Slicer_Syndicatenumber")
            .ClearManualFilter
            For Each SI In .SlicerItems
                SI.Selected = UCase(SI.Value) = UCase(Range("J3").Value)
            Next SI
        End With
    End If
ExitSub:
    Application.EnableEvents = True
End Sub

来源:https://stackoverflow.com/questions/28718295/powerpivot-slicer-selection-based-on-cell-value-using-vba

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!