Remove legend where no data in the chart

bruty

Active Member
Joined
Jul 25, 2007
Messages
456
Office Version
  1. 365
Platform
  1. Windows
I have a doughnut chart that is showing the results for the current quarter next to a column chart which shows the results for the current quarter and previous 2. When there is no data for the current quarter, the doughnut chart does not appear (which is fine) but the legend is still there. This is fine for the column chart as there is normally data in at least one of the 3 quarters shown.

Is there any way to remove or suppress the legend in the doughnut chart when there is no data for the current quarter?

Please note that both charts are fed from the same data, which is a data table that cannot be changed.
 

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.
This code with the chart selected
ActiveChart.Legend.Delete
or this code with the appropriate chart name substituted for 'Chart 3' and with the sheet holding the chart properly referenced
ActiveSheet.ChartObjects("Chart 3").Chart.Legend.Delete

This code will add and position a legend:
ActiveSheet.ChartObjects("Chart 3").Chart.HasLegend = True
ActiveSheet.ChartObjects("Chart 3").Chart.Legend.Position = xlBottom
 
Upvote 0

Forum statistics

Threads
1,223,893
Messages
6,175,240
Members
452,621
Latest member
Laura_PinksBTHFT

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