Extract selected text value on a slicer

MANICX100

New Member
Joined
May 20, 2022
Messages
13
Office Version
  1. 365
Platform
  1. Windows
Assuming I do not allow multi select on a slicer e.g.

Option 1
Option 2

How could I extract the text e.g. Option 2 if selected into a cell.

A quick Google wants either PowerBI / Pivot which is incompatible with my current worksheet setup.
 

Excel Facts

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.
The following code assumes that the workbook running the code contains the slicer, and it assumes that the slicer name (right-click slicer > Slicer Settings > Name to use in formulas) is "Slicer_SlicerName". Change the name accordingly.

Note, even though you don't allow multi-select, it's still possible to select more than one item by holding down the Ctrl key and then clicking on other items. So the code checks whether more than one item is visible. If so, it exits the sub. You may want to change this behaviour accordingly.

VBA Code:
    With ThisWorkbook.SlicerCaches("Slicer_SlicerName") 'change the slicer name accordingly
   
        If .VisibleSlicerItems.Count > 1 Then Exit Sub
       
        Dim itm As SlicerItem
        For Each itm In .SlicerItems
            If itm.Selected = True Then
                Worksheets("Sheet1").Range("B2").Value = itm.Name 'change the cell destination accordingly
                Exit For
            End If
        Next itm
       
    End With

Hope this helps!
 
Upvote 0

Forum statistics

Threads
1,223,230
Messages
6,170,883
Members
452,364
Latest member
springate

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