vba 如果小于一个值,则删除数据标签
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/13886866/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Remove data label if less than a value
提问by Chris2015
I have datalabels I've applied to a chart and now I am trying to remove those lables that are less than 1%. Here is what I have -
我有应用于图表的数据标签,现在我试图删除那些小于 1% 的标签。这是我所拥有的 -
Dim cht As Chart
Set cht = ActiveChart
If Range("B8") < 0.01 Then
cht.SeriesCollection(1).DataLabels.Select
Selection.Delete
End If
I am not quite sure what I am doing wrong, but all the data labels are removed. Do you know why? Thanks!
我不太确定我做错了什么,但所有数据标签都被删除了。你知道为什么吗?谢谢!
回答by Scott Holtzman
You are removing the DataLabels for the entire series in this code.
您正在删除此代码中整个系列的 DataLabels。
What you need to do is remove the DataLabel for the specific point on the series.
您需要做的是删除系列上特定点的 DataLabel。
This should do it:
这应该这样做:
Dim cht As Chart
Set cht = ActiveChart
If Range("B8") < 0.01 Then
cht.SeriesCollection(1).Points(1).DataLabel.Delete
End If
SeriesCollection(1)
is the first series in the chart. Points(1)
is the first point on the chart. Adjust as needed for your code.
SeriesCollection(1)
是图表中的第一个系列。Points(1)
是图表上的第一个点。根据您的代码需要进行调整。