Need to replace existinf graph for new graph with the same name

A

anamarie30

I need to include in this code the following thing.

1. Suppose that a graph called "TEST" already exixt.
2. I run my macro for created a new graph called "TEST".
3. I want that the macro reconized the graph described in step 1 and
replaced it with the new graph described in step 2.

How can I do that? Here it my code:



Sub TEST()

Dim CHT As Chart

Set CHT = Charts.Add
With CHT
.Name = "NC TREND PER SHIFT1"
.ChartType = xlColumnClustered
.SetSourceData Source:=Sheets("NC TREND").Range("B4:G4,B12:G12"),
PlotBy:=xlRows
.HasTitle = True
.ChartTitle.Characters.Text = Sheets("NC Trend").Cells(1, 1)
.Axes(xlCategory, xlPrimary).HasTitle = True
.Axes(xlCategory, xlPrimary).AxisTitle.Characters.Text = "SHIFT"
.Axes(xlValue, xlPrimary).HasTitle = True
.Axes(xlValue, xlPrimary).AxisTitle.Characters.Text = "AVERAGE NC"
.HasLegend = False
.SeriesCollection(1).HasDataLabels = True
End With

With ActiveChart.Axes(xlValue)
.MinimumScaleIsAuto = True
.MaximumScale = 10
.MinorUnitIsAuto = True
.MajorUnitIsAuto = True
.Crosses = xlAutomatic
.ReversePlotOrder = False
.ScaleType = xlLinear
.DisplayUnit = xlNone
End With

End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top