系列删除图表

时间:2017-07-28 09:05:33

标签: excel vba excel-vba

我有一张桌子,想要生成一张图表。问题是我想只有A,F,G和H的列值。

我尝试了seriescollection(1).deletion方法。但我仍在我的图表中获得B和C系列。

有人能告诉我怎么做。 任何领导都会有所帮助

Sub chartstatus()
Dim Rng As Range
Dim cht As Object

Set Rng = ActiveSheet.Range("A2:H53")
ThisWorkbook.Sheets("Status").ChartObjects.delete
Set Sh = ActiveSheet.ChartObjects.Add(Left:=650, _
    Width:=600, _
    Top:=80, _
    Height:=250)

Sh.Select

Set cht = ActiveChart
With cht
.SetSourceData Source:=Rng
.ChartType = xlColumnClustered
cht.Axes(xlSecondary).TickLabels.NumberFormat = "0.%"

End With


cht.SeriesCollection(6).Name = " % Missing "
cht.SeriesCollection(7).Name = " % OnTime"
cht.SeriesCollection(8).Name = " %  Delayed"


cht.SeriesCollection(6).HasDataLabels = True
cht.SeriesCollection(7).HasDataLabels = True
cht.SeriesCollection(8).HasDataLabels = True
cht.SeriesCollection(1).Format.Fill.ForeColor.RGB = RGB(255, 255, 255) '<~~ Red

cht.HasTitle = True
cht.ChartTitle.Text = "Result "
End Sub

1 个答案:

答案 0 :(得分:3)

您可以将2个范围合并为1个范围

Dim Rng As Range
Dim Rng_A As Range
Dim Rng_FH As Range
Set Rng_A = ActiveSheet.Range("A2:A52")
Set Rng_FH = ActiveSheet.Range("F2:H52")
Set Rng = Union(Rng_A, Rng_FH)