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