VBA to deselect single slicer item using data model pivot table

MA54

New Member
Joined
Apr 13, 2020
Messages
2
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
Hi VBA masters, I am a first time poster to Mrexcel, and a VBA newbie.
I am trying to use a macro to send the user to a hidden Sheet1, hide the current sheet called HOME, and select a slicer item ("LA"), and deselect the other items. Slicer has three items: CA, LA, MI.
Initially all three items are selected, until the user hits the macro.
Slicer name is SLICER_DC.

The slicer is connected to a PivotTable that comes from a data model.
I have a macro that sends the user to Sheet1 and it works no problem.
I just couldn't get the slicer to select LA, and deselect CA and MI.

I tried the approach below as a module but I couldn't get it to work.
The error code I get is: "Invalid procedure call or argument."

Could someone please help point me in the right direction?

Thank you!

VBA Code:
Sub Slicer()


    Sheets("HOME").Select
    Sheets("Sheet1").Visible = True
    Sheets("Sheet1").Select

ActiveWorkbook.SlicerCaches("SLICER_DC").ClearManualFilter
  With ActiveWorkbook.SlicerCaches("SLICER_DC1")
        .SlicerItems("LA").Selected = True
        .SlicerItems("MI").Selected = False
        .SlicerItems("CA").Selected = False



    End With

End Sub
 

Excel Facts

Does the VLOOKUP table have to be sorted?
No! when you are using an exact match, the VLOOKUP table can be in any order. Best-selling items at the top is actually the best.

Forum statistics

Threads
1,214,960
Messages
6,122,479
Members
449,088
Latest member
Melvetica

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