How to change or set Doughnut chart legends via VBA

QuestionBaker

Board Regular
Joined
Apr 12, 2019
Messages
106
Office Version
  1. 365
Platform
  1. Windows
I have to delete the ranges from where I am plotting my doughnut chart, I am able to preserve the data using the following code

VBA Code:
For Each srs In doughnut.Chart.SeriesCollection
        srs.Values = srs.Values
Next
but not the legend, is there a way I can overwrite the legend or unlink the complete chart from source data?
 

Excel Facts

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple
I hope this will help
I have the legends in my chart, but when I delete the underlying data legend text also gets deleted.
I want a way to delete the data, and not have the legend text deleted.
I know what text should go for the legends, so I can also get away by hard coding it.
 
Upvote 0
Try something like this but has to set HasDataLabels = True first
ActiveChart.SeriesCollection(1).Name = Your Text Here
 
Upvote 0
Try something like this but has to set HasDataLabels = True first
ActiveChart.SeriesCollection(1).Name = Your Text Here
Throws with object variable or with block variable not set error.
I have one more option, I need the chart in a ppt
I can check if deleting the data after pasting the chart in ppt preserves the chart.
I will update if this works or not once I try it out
 
Upvote 0
After experimenting with recorded macros, I found the following code to work for me
VBA Code:
ActiveChart.Chart.FullSeriesCollection(1).XValues = "={""Concept"",""Delivery""}"
 
Upvote 0
Solution
Good that you have found solution. I'm not much into chart but many commands for chart have no Intellisense aid. Even I found many commands suggested do not work. Probably due to older version, I'm not sure. :)
 
Upvote 0

Forum statistics

Threads
1,215,844
Messages
6,127,245
Members
449,372
Latest member
charlottedv

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