Jenny
Jenny

Reputation: 451

series deletion in chart

I have an table and would like to generate an chart out of it. the problem is I would like to have only the column Values of A, F, G, and H.

I tried seriescollection(1).deletion method,. but I am still getting the column B and C series in my chart.

Could anyone tell me how I can do it. Any lead would be helpful

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

Upvotes: 2

Views: 61

Answers (1)

kevin
kevin

Reputation: 183

You can combine 2 range into 1 range

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)

Upvotes: 3

Related Questions