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

Select all contiguous cells
Pressing Ctrl+* (asterisk) will select the "current region" - all contiguous cells in all directions.
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,213,510
Messages
6,114,034
Members
448,543
Latest member
MartinLarkin

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