Hello there!
I am hoping to get some code for the following challenge:
I have a slicer on Sheet1 that controls a pivot on Sheet2, and the results are then read to a table on Sheet1. I have another Slicer on Sheet3 that controls a pivot on Sheet3. The field names are the same (Region) regardless of the slicer. I have 12 different Regions in that field. I would like to do a count of the number of selected items. If that item is 12, then hide a row. If the number of selected items is anything but 12, then I want to show the row (row 10). Here is some code that I had before, that works sometimes, but not for a particular Region for some reason:
The code above works for the first example (I have a slicer on Sheet1 that controls a pivot on Sheet2, and the results are then read to a table on Sheet1.) For the second example, one of the Regions (the last one) is not recognized - it hides the row no matter what. I am thinking to avoid this, I can do the count selected items solution I mentioned in the first part of my post, but I am open to any ideas on how to correct this.
Thank you so much for your help.
Excel 2016/Windows 10
I am hoping to get some code for the following challenge:
I have a slicer on Sheet1 that controls a pivot on Sheet2, and the results are then read to a table on Sheet1. I have another Slicer on Sheet3 that controls a pivot on Sheet3. The field names are the same (Region) regardless of the slicer. I have 12 different Regions in that field. I would like to do a count of the number of selected items. If that item is 12, then hide a row. If the number of selected items is anything but 12, then I want to show the row (row 10). Here is some code that I had before, that works sometimes, but not for a particular Region for some reason:
VBA Code:
Sub Hide_Unhide_facility()
Application.ScreenUpdating = False
Dim cache As Excel.SlicerCache
Dim sht As Worksheet
Dim sItem As Excel.SlicerItem
Set cache = ActiveWorkbook.SlicerCaches("Slicer_Region1")
For Each sItem In cache.SlicerItems
Rows(10).Hidden = sItem.Selected
Next
Application.ScreenUpdating = True
End Sub
The code above works for the first example (I have a slicer on Sheet1 that controls a pivot on Sheet2, and the results are then read to a table on Sheet1.) For the second example, one of the Regions (the last one) is not recognized - it hides the row no matter what. I am thinking to avoid this, I can do the count selected items solution I mentioned in the first part of my post, but I am open to any ideas on how to correct this.
Thank you so much for your help.
Excel 2016/Windows 10