I am wondering how can I insert the slicer into the userform after creating the pivot table in excel 2016.
Inserting slicer means clickable slicer, not image..
Could anyone show me some example vba code? Thanks in advance
I am wondering how can I insert the slicer into the userform after creating the pivot table in excel 2016.
Inserting slicer means clickable slicer, not image..
Could anyone show me some example vba code? Thanks in advance
You must have achieved what you wanna do by now but anyway...
Create unique data as range or array somehow and put them in ListBox when initialize your form. Or try adding every row into the ListBox while cheking it's not in there yet.
I avoided latter or any counting by copying range to newly created sheet because my data can be large. So I used RemoveDuplicates method.
You can also use Advancedfilter for non-table data.
*adjust ranges to yours
Private Sub UserForm_Initialize()
Application.DisplayAlerts = False
Dim i As Long
ThisWorkbook.Worksheets("Sheet1").ListObjects(1).ListColumns(3).Range.Copy ''my table#1's column3
Sheets.Add.Visible = False
With ActiveSheet.Previous
.Range("A1").PasteSpecial
.Range("A1").CurrentRegion.RemoveDuplicates 1, xlYes
For i = 2 To .Cells(Rows.Count, 1).End(xlUp).Row
ListBox1.AddItem .Cells(i, 1)
Next i
.Delete
End With
Application.DisplayAlerts = True
End Sub
Then you can set autofilter with what's/'re selected on the ListBox.