3

我有很多表,每个表都有一个图表,我想遍历每个图表中的每个数据标签,删除任何等于 0,但似乎无法提取数据标签值。

With ActiveChart
    For k = 1 To .SeriesCollection.Count
        For j = 1 To .SeriesCollection(k).Points.Count
            For l = 1 To .SeriesCollection(k).Points(j).DataLabels.Count
               If .SeriesCollection.Points(j).DataLabels(l) = 0 Then
                   .SeriesCollection.Points(j).DataLabel(l).Delete
                End If
            Next l
        Next j
    Next k
End With

(忽略通过激活每个图表的每张表的循环,该位有效,因此保持代码示例最小)

谁能建议如何循环数据标签,检查值并在适当的地方删除?

4

1 回答 1

4

你很亲近!

您只是错过了.Caption检查DataLabel

我改为DataLabels(l)DataLabels.Item(l)你的代码有一个反复无常)。

With ActiveChart
    For k = 1 To .SeriesCollection.Count
        For j = 1 To .SeriesCollection(k).Points.Count
            For l = 1 To .SeriesCollection(k).Points(j).DataLabels.Count
               If .SeriesCollection.Points(j).DataLabels.Item(l).Caption = 0 Then
                   .SeriesCollection.Points(j).DataLabels.Item(l).Delete
                End If
            Next l
        Next j
    Next k
End With

OP使用的最终代码:

With ActiveChart
    For k = 1 To .SeriesCollection.Count
        For j = 1 To .SeriesCollection(k).Points.Count
            If .SeriesCollection(k).Points(j).DataLabel.Caption = 0 Then
                .SeriesCollection(k).Points(j).DataLabel.Delete
           End If
        Next j
    Next k
End With
于 2017-01-31T14:25:59.210 回答