删除图表中的空白行值

时间:2017-08-03 21:43:44

标签: excel vba excel-vba

我正在从表中生成图表。表行未完全填充。

因此,当我生成图表时,我将未填充列的值也作为" 0"。我想删除" 0" (我的图表中的空行和#34;的值)。是 我有办法做到这一点吗?任何领导都会有所帮助

Sub chartResult()
Dim rng As Range
Dim cht As Object
Set rng = ActiveSheet.Range("B2:D53")
 ThisWorkbook.Sheets("Result").ChartObjects.delete
 Set sh = ActiveSheet.ChartObjects.Add(Left:=440, _
    Width:=600, _
    Top:=340, _
    Height:=250)
 sh.Select
 Set cht = ActiveChart
With cht
 .SetSourceData Source:=rng
 .ChartType = xlColumnClustered
End With
 cht.SeriesCollection(1).name = "Ov"
 cht.SeriesCollection(2).name = "O"
 cht.SeriesCollection(3).name = "To"

 cht.SeriesCollection(1).HasDataLabels = True
 cht.SeriesCollection(2).HasDataLabels = True
 cht.SeriesCollection(3).HasDataLabels = True
 cht.SeriesCollection(1).Format.Fill.ForeColor.RGB = RGB(72, 118, 255)  '<~~ Red
 cht.SeriesCollection(2).Format.Fill.ForeColor.RGB = RGB(255, 0, 0)
 cht.SeriesCollection(3).Format.Fill.ForeColor.RGB = RGB(0, 167, 0)
 cht.HasTitle = True
 cht.ChartTitle.Text = "Result "
End Sub

this is the sample image of my graph. I would like to remove all the zero values.IS there a way  could do

2 个答案:

答案 0 :(得分:0)

尝试使用属性Chart.DisplayBlanksAs并设置xlNotPlotted

因此,在代码中,更改会在with语句中显示如下所示的内容。

With cht
 .SetSourceData Source:=rng
 .ChartType = xlColumnClustered
 .DisplayBlanksAs = xlNotPlotted  //ADD THIS STAEMENT.
End With

答案 1 :(得分:0)

@Jenny - 我不能保证这会有效,我不会使用图表,但试一试。

With cht
 .SetSourceData Source:=rng
 .ChartType = xlColumnClustered
 .PivotItems("0").Visible = False
End With