Macro to set .sliceritems to True for one selections and all others to False

stevejb

New Member
Joined
Feb 16, 2016
Messages
1
Hello,
I have several buttons on my Spreadsheet that use different macros to open details view using Slicer tables.
I'm having an issue that periodically the selections within the Slicer may change or one item doesn't exist.

When a value doesn't exist within the slicer, I get a runtime error and have to remove that selection or tweak the data to add bogus info.
it may exist in Program, but not in Program2.

I want to identify the single sliceritem as True and ALL OTHERS as false.

Below is an example of the macro as it was created when I used the Record macro option:

Code:
 Sub Button_details()
 '
 ' Button_details Macro
 '

 With ActiveWorkbook.SlicerCaches("Slicer_Program")
 .SlicerItems("ABC").Selected = False
 .SlicerItems("CBA").Selected = False
 .SlicerItems("XYZ").Selected = True
 .SlicerItems("#N/A").Selected = False
 .SlicerItems("(blank)").Selected = False
 End With
 With ActiveWorkbook.SlicerCaches("Slicer_Program2")
 .SlicerItems("ABC").Selected = False
 .SlicerItems("XYZ").Selected = True
 .SlicerItems("CBA").Selected = False 
 .SlicerItems("#N/A").Selected = False
 .SlicerItems("(blank)").Selected = False
 End With

Thanks in advance for any ideas/input.
 

Excel Facts

Can a formula spear through sheets?
Use =SUM(January:December!E7) to sum E7 on all of the sheets from January through December

Forum statistics

Threads
1,223,248
Messages
6,171,021
Members
452,374
Latest member
keccles

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