Count Slicer Items when a second slicer item is selected

SiGill1979

New Member
Joined
Oct 13, 2016
Messages
3
I have a table in my spreadsheet with 2 slicers.

When an item is selected in Slicer 1 I want to count the number of slicer items in Slicer 2.
The code I have counts all the items in slicer 2 rather than just the filtered ones. How can I count just the filtered ones?

This is my code

Sub Slicers()

Application.ScreenUpdating = False

Dim strWeek As String
Dim intSlicerCount As Integer
Dim i As Integer

Application.Volatile

strWeek = InputBox("Please input the Arrival Week required")

intSlicerCount = ActiveWorkbook.SlicerCaches("Slicer1").SlicerItems.Count

ActiveWorkbook.SlicerCaches("Slicer1").ClearManualFilter

For i = 1 To intSlicerCount
With ActiveWorkbook.SlicerCaches("Slicer1")
If i = strWeek Then
.SlicerItems(i).Selected = True
Else
.SlicerItems(i).Selected = False
End If
End With
Next i

intSlicerCount = ActiveWorkbook.SlicerCaches("Slicer2").VisibleSlicerItems.Count

MsgBox intSlicerCount

Application.ScreenUpdating = True

End Sub
 

Excel Facts

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.
I think you need to count the HasData items:
VBA Code:
    Dim numSlicer2 As Long
    numSlicer2 = 0
    With ActiveWorkbook.SlicerCaches("Slicer2")
        For i = 1 To .VisibleSlicerItems.Count
            If .SlicerItems(i).HasData Then numSlicer2 = numSlicer2 + 1
        Next
    End With

    MsgBox numSlicer2
 
Upvote 0

Forum statistics

Threads
1,214,911
Messages
6,122,199
Members
449,072
Latest member
DW Draft

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top