title: Deleting empty Series out of Graph (with VBA)
body: <p>I am trying to remove all empty series out of an Excel graph.</p>
  
  <pre><code>    Dim isEmptySeries As Boolean
      For Series = 1 To .SeriesCollection.count
          .SeriesCollection(Series).ApplyDataLabels Type:=xlDataLabelsShowValue, AutoText:=True, LegendKey:=False
          isEmptySeries = True
  
          For i = 1 To .SeriesCollection(Series).points.count
              If .SeriesCollection(Series).points(i).DataLabel.Text = 0 Then
                  .SeriesCollection(Series).points(i).HasDataLabel = False
              Else
                  isEmptySeries = False
                  .SeriesCollection(Series).points(i).DataLabel.Font.Size = 17
              End If
          Next i
  
          If isEmptySeries Then
                  .SeriesCollection(Series).Delete
          End If
      Next Datenreihe
  </code></pre>
  
  <p>The script fails at the ApplyDatalabels line ("Method SeriesCollection of Object Chart failed").
  I believe that Excel shifts the Series indexes when one of the Series is deleted? Is that the case? It's the only explanation that I have for the error.</p>
  
  <p>How else would I loop through the series and remove the ones that are empty?</p>