Rename a data series in a Box and Whisker chart - Macro or VBA

PaulClarke

New Member
Joined
Aug 13, 2021
Messages
2
Office Version
  1. 2019
Platform
  1. Windows
I need to automate the operation described in the Microsoft Support page Rename a data series
I need to do this only on Box and Whisker charts.
For example:

Before.png


To get from the chart above to the chart below is easily performed manually

After.png


Recording a macro of the operation of that example gives:

*****

Sub Macro3()


' Macro3 Macro


ActiveChart.FullSeriesCollection(2).Select

Application.CutCopyMode = False

ActiveChart.FullSeriesCollection(1).Name = "=""1"""

ActiveChart.FullSeriesCollection(2).Name = "=""2"""

ActiveChart.FullSeriesCollection(3).Name = "=""3"""

End Sub

*****

When played back, the macro does not complete (it hangs part way through).

This example includes only 3 values. My projects involve dozens of values to rename in the same B&W chart - in order to reduce the size of the legend (deleting the repetition of the word ‘Series’) – and many, many charts.

If anyone can help with a macro that works, I can then add lines of code to handle the repetitions.

Here's hoping !

With thanks,
Paul
 

Excel Facts

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.
Hi and welcome!

Especially if you are potentially working with multiple charts, but even if not, I would definitely recommend against using ActiveChart or any other similar Active or Selected object - you can easily run into trouble when everything is a "relative" reference. It is much better practice overall, and it makes it easier to debug and read code when you refer to a chart specifically (see below for an example).

Anyways, to rename a chart series, the best way to do that is like this answer. If you're renaming dozens of series on a chart, it may be helpful to loop through them all
VBA Code:
Sub RenameChartSeries_1179067()
    Dim boxchart As chart
    Dim idx As Integer
    Set boxchart = ThisWorkbook.Worksheets("1179067").ChartObjects(1).chart
    
    For idx = 1 To boxchart.SeriesCollection.Count
        boxchart.SeriesCollection(idx).Name = "renamed " & idx
    Next idx
End Sub
 
Upvote 0
Solution
Thank you severynm. In fact, I managed to solve my problem before you replied yesterday - using the coding you suggested - and in a loop :).
 
Upvote 0

Forum statistics

Threads
1,214,981
Messages
6,122,565
Members
449,089
Latest member
Motoracer88

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