• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

VBA to select slicer item using data model table and hide current sheet and unhide sheet with the slicer

AM94

New Member
Hi VBA masters, I am a first time poster to chandoo, 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!


Code:
Sub Slicer()


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

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



    End With

End Sub
 
Last edited:
Nevermind.. The code works.
I was getting an error because I mis-spelt the slicer name in the code. :rolleyes:
 
Back
Top