Count Slicer Items when a second slicer item is selected

SiGill1979

New Member
Joined
Oct 13, 2016
Messages
1
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

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.

John_w

MrExcel MVP
Joined
Oct 15, 2007
Messages
6,769
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
 

Watch MrExcel Video

Forum statistics

Threads
1,130,418
Messages
5,642,009
Members
417,250
Latest member
spr1nger

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
Top