Possible to list selected slicer values in cell?

largeselection

Active Member
Joined
Aug 4, 2008
Messages
358
Hi,

So I found some info online which outlines a routine to display messageboxes which show the items contained in a slicer.

What I want to know is:
1) Is it possible to only list the items that are selected in a slicer?

2) If part 1 is possible, is it then possible to list them in a string to put in a cell?


Basically if I have say 3 slicers over a report "NAME", "YEAR", "STATE", I want the report to display a text row at the top (or even a header/footer might work) which says what has been selected.

I know I can just print out the report with the slicers visible, but I actually have many slicers and might be selecting items that are not visible within the same slicer box window.

So rather than having to type what I selected manually, I'd want it to just show in a line above the report:

Name: Henry, Carl, Joe / Year: 2011 / State: NY, NJ, NM, CA

and have it update based on whatever is selected in the slicers.

Any thoughts on how to accomplish this?

I've listed the code from Microsoft's website below which shows how to list all of the items (all items, not only selected items) in messageboxes for reference.

Rich (BB code):
dim cache As Excel.slicerCache
Set cache = ActiveWorkbook.SlicerCaches("Slicer_Sales_Type")
Dim sItem As Excel.SlicerItem
For Each sItem In cache.SlicerItems
MsgBox sItem.Name
Next sItem


</PRE>




</PRE>

THANKS!


</PRE>
 

Excel Facts

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.
You probably figured this out or came to a workaround, but I thought I'd post this for people like me who are searching for similar answers.

You can just add an if statement to check if sitem.selected = True

Code:
Sub SelectedSlicers()

Dim cache As Excel.SlicerCache
Set cache = ActiveWorkbook.SlicerCaches("Slicer_Sales_Type)
Dim sItem As Excel.SlicerItem
For Each sItem In cache.SlicerItems
If sItem.Selected = True Then MsgBox sItem.Name
Next sItem
End Sub

Then instead of a message box, just have it write somewhere, either a variable to concatenate later or a cell.
 
Upvote 0
Hey I have used a workaround, but this is much better so thanks for responding after so long!

I've gotten it to put the values in a list of cells in the worksheet, but is there a way to do that only if the selected items count to less than the total that are available?

Basically, I only want the items to populate in the worksheet when the code is run if there are less items selected than are available, because I don't want to fill the sheet with values because nothing is selected (so by default technically everything is "selected")
 
Upvote 0
Spoke too soon...

So it worked on a test file, but it failed when I tried to put the same code on the actual file. The test file consisted of dummy data that I input, the actual file is connected to an OLAP cube.

The code I used is below:
Code:
Sub RevisedSlicers()
Dim sAvail As Long
Dim sSelect As Long
Dim cache As Excel.SlicerCache
Set cache = ActiveWorkbook.SlicerCaches("Slicer_TYPE")
Dim sItem As Excel.SlicerItem
sAvail = 0
sSelect = 0
For Each sItem In cache.SlicerItems
sAvail = sAvail + 1
If sItem.Selected = True Then Range("B5000").End(xlUp).Offset(1, 0).Value = sItem.Value
sSelect = sSelect + 1
Next sItem
If Range("B20").Value < sAvail Then
Exit Sub
End If
Range("B22:B5000").ClearContents
End Sub

That worked fine in the test workbook, but not in the actual one - I'm guessing it has something to do with the fact that one is an OLAP pivot table and one is not. Any ideas?

I'm getting an "Application defined or object defined error" at the row where it says "For Each sItem In cache.SlicerItems"
 
Upvote 0
I'm pretty new to slicers but I did find this to get a count.

SlicerCache.SlicerItems.count

However, according to the help documents, that won't work with OLAP and you need to use SlicerCacheLevel. I think the help might be able to put you on the right track. Sorry I can't be of more use.
 
Upvote 0
That is a bummer. I read the help info and tried some stuff to no avail. I guess I'll keep tinkering with it when I can and keep the workaround I've been using for now.

Thanks for your help again!
 
Upvote 0
What I want to know is:
2) If part 1 is possible, is it then possible to list them in a string to put in a cell?

Hi
I know this is an old post but for others this may help.

I use slicers but to do what you want I use a combination of pivot tables and a simple piece of VBA that I stole from Chandoo (How to add a range of cells in excel – concat() | Chandoo.org - Learn Microsoft Excel Online)

I have an example using the slicers and names from this thread here
https://app.box.com/s/buxal4ebcewl7i0jz421qjl8xp4tom0o


HTH

Martin
 
Upvote 0

Forum statistics

Threads
1,223,914
Messages
6,175,351
Members
452,638
Latest member
Oluwabukunmi

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