I need help with VBA code for an ActiveX Button that uses a Slicer to filter a worksheet.

Hello, I need some code that does the following with the triggers listed. I wrote my idea of what the code might look like. Thanks.

User Input:
1. The user selects a record from a Slicer
2. The user clicks an ActiveX Button to navigate to another sheet within the workbook.

Macro:
1. The sheet automatically filters the data to show only the records which apply to the value which the user selected from the Slicer.

 With ActiveWorkbook.SlicerCaches("Slicer_Author")
          .SlicerItems("WHATEVER THE USER CHOSE").Selected = True
          Sheets("Contributor-Dashboard").Select
          ActiveSheet.Range("$A$1:$N$82448").AutoFilter Field:=3, Criteria1:= _
        "WHATEVER THE USER CHOSE"
End With
Contributor-Dashboard-Dummy-Data.xlsm
calyx_terenAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Rgonzo1971Commented:
Hi,

pls try

Sub Macro
For Each Item In ActiveWorkbook.SlicerCaches("Slicer_Author").VisibleSlicerItems
        strArray = strArray & Item.Value & ","
    Next
    strNames = Left(strArray, Len(strArray) - 1)
    aNames = Split(strNames, ",")

    If UBound(aNames) = 0 Then
        Sheets("DummyData").Range("A1:I100000").AutoFilter Field:=3, Criteria1:=aNames
    Else
        Sheets("DummyData").Range("A1:I100000").AutoFilter Field:=3, Criteria1:=aNames, Operator:=xlFilterValues
    End If
End Sub

Open in new window

Regards
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Rory ArchibaldCommented:
Not for points

FWIW, you don't need the If:

    anames = Split(strNames, ",")
    Sheets("DummyData").Range("A1:I100000").AutoFilter Field:=3, Criteria1:=anames, Operator:=xlFilterValues

Open in new window

0
calyx_terenAuthor Commented:
Thanks for your help, Rory. It works. I did make some small changes to have the script open the sheet that it filters and changed the  heading of the script. Ultimately, this is what I used.

Private Sub CommandButton1_Click()
For Each Item In ActiveWorkbook.SlicerCaches("Slicer_Author").VisibleSlicerItems
        strArray = strArray & Item.Value & ","
    Next
    strNames = Left(strArray, Len(strArray) - 1)
    aNames = Split(strNames, ",")

    If UBound(aNames) = 0 Then
        Sheets("DummyData").Range("A1:I100000").AutoFilter Field:=3, Criteria1:=aNames
    Else
        Sheets("DummyData").Range("A1:I100000").AutoFilter Field:=3, Criteria1:=aNames, Operator:=xlFilterValues
    End If
 
    Sheets("DummyData").Range("A1:I100000").AutoFilter Field:=3, Criteria1:=aNames, Operator:=xlFilterValues
    Sheets("DummyData").Select

End Sub
0
Rgonzo1971Commented:
Hi,

Why not simply use

Private Sub CommandButton1_Click()
    For Each Item In ActiveWorkbook.SlicerCaches("Slicer_Author").VisibleSlicerItems
        strArray = strArray & Item.Value & ","
    Next
    strNames = Left(strArray, Len(strArray) - 1)
    aNames = Split(strNames, ",")
    Sheets("DummyData").Activate
    Range("A1:I100000").AutoFilter Field:=3, Criteria1:=aNames, Operator:=xlFilterValues
End Sub

Open in new window

Regards
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Excel

From novice to tech pro — start learning today.