Chart title link to slicer

MimiM

New Member
Joined
Apr 23, 2018
Messages
24
Hi all

I have searched the forum for Dynamic Chart Title, but all I've found is the standard link to a cell or a formula linked to a cell.

I have a chart based on a pivot table, and a Slicer based on one of the fields, Clinician. I should like the chart title to include the name of the clinician selected in the Slicer.

Is this possible at all please?

Thank you in advance

Mimi
 

Excel Facts

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.
If you add Clinician as a filter on the pivot, you could just reference that cell for the chart title. This will change with the slicer selection.
 
Last edited:
Upvote 0
Or:

*just record a macro and change the slicer to find the SlicerCaches name

Code:
Sub renamechart()


Dim cache As Excel.SlicerCache
Set cache = ActiveWorkbook.SlicerCaches("Slicer_Contract_Obligation")  'update
Dim sItem As Excel.SlicerItem
    For Each sItem In cache.SlicerItems
        If sItem.Selected = True Then
        GoTo setname
        End If
    Next sItem
    Exit Sub


setname:
    ActiveSheet.ChartObjects("Chart 2").Activate  'update
    ActiveChart.ChartTitle.Select
    ActiveChart.ChartTitle.Text = sItem.Name


End Sub
 
Upvote 0
Thanks - but I'm hopeless at VBA. How would I record the code above, step by step, please? I seem to have recorded the sub under a macro but when I try to run, it comes up with Error 5 - invalid procedure call or argument. Highlights the row where I update the slicer name in the cache. And yes, I have used the name of the slicer in the workbook, "Clinician"
 
Upvote 0
Sounds sorted, but just to answer your question.

Go to Developer>Record Macro, press alt+F11 to open the VBA editor.

Make a selection on a slicer. You should see code like:

Code:
With ActiveWorkbook.SlicerCaches("Slicer_1")        
       .SlicerItems("1").Selected = True
End With

Change
Code:
[COLOR=#333333]SlicerCaches("Slicer_Contract_Obligation")[/COLOR]
to
Code:
[COLOR=#333333]SlicerCaches("Slicer_1")[/COLOR]
 
Last edited:
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

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