goncalogera
New Member
- Joined
- Nov 10, 2020
- Messages
- 14
- Office Version
- 2019
- Platform
- Windows
- Mobile
- Web
I've a slicer called "Selecione um ano" that filters the data in a table called "Vendas2020". What I want to do now is to extract the selection(s) made on the filter (which can go from 2015 to current year) and print them as a list in any given cell but I can't seem to make the code work. This list has to update each time the selection(s) on the list are changed.
I've adapted a code I've found in many answers on similar questions but my knowledge isn't much so there has to be something missing in my adaptation.
Here is my code:
Thanks for your help!
I've adapted a code I've found in many answers on similar questions but my knowledge isn't much so there has to be something missing in my adaptation.
Here is my code:
VBA Code:
Dim sl2 As Slicer
Dim sc2 As SlicerCache
Set sc2 = ThisWorkbook.SlicerCaches.Add2(ws.ListObjects("Vendas2020"), "Ano")
Set sl2 = sc2.Slicers.Add(wr, , "Ano", "Selecione um ano")
Dim cache As Excel.SlicerCache
Set cache = ActiveWorkbook.SlicerCaches("Selecione um ano")
Dim sItem As Excel.SlicerItem
For Each sItem In cache.SlicerItems
If sItem.Selected = True Then MsgBox sItem.Name
Next sItem
Thanks for your help!