2

我正在尝试从 Excel 图表中删除所有空系列。

    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

脚本在 ApplyDatalabels 行失败(“方法 SeriesCollection of Object Chart 失败”)。我相信当一个系列被删除时,Excel会改变系列索引?是这样吗?这是我对错误的唯一解释。

我还能如何遍历该系列并删除那些为空的?

4

1 回答 1

5

在这些情况下尝试以相反的顺序循环

For i = .SeriesCollection(Series).points.count To 1 Step -1

这样.Delete不会影响尚未循环的项目

于 2011-10-25T06:06:54.473 回答