Hi - I would like to set this slicer up so that activates a macro depending on which box i select below - eg if select the planners box it activates a macro called "Planning_Staff"
Ive been offered this as a solution but nothing happens when i click the Planners box
for info i can confirm that the name of the slicer is "ROLE" and there is a macro in the workbook entitled "Planning_Staff"
Private Sub Workbook_SheetPivotTableUpdate(ByVal Sh As Object, ByVal Target As PivotTable)
Dim ws As Worksheet
Dim slicer As slicer
Dim selectedSlicerItem As SlicerItem
'Specify the name of the worksheet containing the slicer
Set ws = ThisWorkbook.Sheets("GRAPHS") 'Replace "Sheet1" with the actual name of your worksheet
'Check if the sheet contains a slicer with the specified name
On Error Resume Next
Set slicer = ws.Slicers("ROLE")
On Error GoTo 0
'Exit if the specified slicer doesn't exist on the sheet
If slicer Is Nothing Then Exit Sub
'Check if the slicer has any selected items
If slicer.SlicerCache.VisibleSlicerItems.Count > 0 Then
'Loop through selected items
For Each selectedSlicerItem In slicer.SlicerCache.VisibleSlicerItems
'Check if the selected item is "Planners"
If selectedSlicerItem.Name = "Senior PM" Then
'Call the macro for "Planners"
Call Planning_Staff
Exit For 'Exit the loop after finding "Planners"
End If
Next selectedSlicerItem
End If
End Sub
Ive been offered this as a solution but nothing happens when i click the Planners box
for info i can confirm that the name of the slicer is "ROLE" and there is a macro in the workbook entitled "Planning_Staff"
Private Sub Workbook_SheetPivotTableUpdate(ByVal Sh As Object, ByVal Target As PivotTable)
Dim ws As Worksheet
Dim slicer As slicer
Dim selectedSlicerItem As SlicerItem
'Specify the name of the worksheet containing the slicer
Set ws = ThisWorkbook.Sheets("GRAPHS") 'Replace "Sheet1" with the actual name of your worksheet
'Check if the sheet contains a slicer with the specified name
On Error Resume Next
Set slicer = ws.Slicers("ROLE")
On Error GoTo 0
'Exit if the specified slicer doesn't exist on the sheet
If slicer Is Nothing Then Exit Sub
'Check if the slicer has any selected items
If slicer.SlicerCache.VisibleSlicerItems.Count > 0 Then
'Loop through selected items
For Each selectedSlicerItem In slicer.SlicerCache.VisibleSlicerItems
'Check if the selected item is "Planners"
If selectedSlicerItem.Name = "Senior PM" Then
'Call the macro for "Planners"
Call Planning_Staff
Exit For 'Exit the loop after finding "Planners"
End If
Next selectedSlicerItem
End If
End Sub