How to remove empty values from 3D area chart with VBA

Viewed 37

So, originally I have a 2D area chart that I generate with VBA that looks like this

enter image description here

This chart is ignoring the legend for any values that are a blank space or a blank cell and the way I do this is with the following code.

Dim i As Long
Dim cht As Chart
Dim lgd As Legend
 Set cht = ActiveChart
   Set lgd = cht.Legend
   For i = lgd.LegendEntries.Count To 1 Step -1
 
         Select Case cht.SeriesCollection(i).Name
 
         Case "Total", ""
                 lgd.LegendEntries(i).Delete
 
          Case "Total", " "
                 lgd.LegendEntries(i).Delete
 
         Case Else
               ' do nothing
         End Select
 
   Next

So this part works perfectly. My issue is that when I take this chart and convert it into a 3D area chart by changing the following code

from this

ActiveSheet.Shapes.AddChart2(276, xlArea).Select

to this

ActiveSheet.Shapes.AddChart2(276, xl3DArea).Select

Then I get the following chart, which shows me everything on my table and I want to get it to hide everything that is a blank space or a blank cell.

enter image description here

I use the exact same code to create the 2D and the 3D chart and I'm not sure why for the 2D chart it hides the empty values correctly but for the 3D chart it breaks and gives me that horrible chart.

0 Answers
Related