Chart Identification Problems

L

lopsided

Hi,

I have a macro which creates new workbooks with charts on them. One o
these charts on each workbook has 3 series' on them, however, some o
these different workbooks have only got data for 1 or 2 of thes
series'. When the code gets to where it shoudl rename the empty serie
I get an error. If I try to then test to see if the name is what i
should be with an If statement it says - unable to get the nam
property of the series class. Hope someone can help!

On Error Resume Next
Set myChart = Worksheets("Sheet1").ChartObjects.Add(chartLeft
chartTop, "384", "166")
With myChart.chart
.ChartType = xlLineMarkers

.SeriesCollection.NewSeries
.SeriesCollection(1).XValues = "='[Kit_Tracker.xls]Charge
Breakdown'!R3C3:R3C" & varIP + 2
.SeriesCollection(1).Values = "='[Kit_Tracker.xls]Charge
Breakdown'!R" & varBreakdownRow & "C3:R" & varBreakdownRow & "C"
varIP + 2
.SeriesCollection(1).Name = "=""Lan PCs"""

.SeriesCollection.NewSeries
.SeriesCollection(2).XValues = "='[Kit_Tracker.xls]Charge
Breakdown'!R3C3:R3C" & varIP + 2
.SeriesCollection(2).Values = "='[Kit_Tracker.xls]Charge
Breakdown'!R" & varBreakdownRow + 1 & "C3:R" & varBreakdownRow + 1
"C" & varIP + 2
.SeriesCollection(2).Name = "=""Laptops"""

.SeriesCollection.NewSeries
.SeriesCollection(3).XValues = "='[Kit_Tracker.xls]Charge
Breakdown'!R3C3:R3C" & varIP + 2
.SeriesCollection(3).Values = "='[Kit_Tracker.xls]Charge
Breakdown'!R" & varBreakdownRow + 2 & "C3:R" & varBreakdownRow + 2
"C" & varIP + 2
.SeriesCollection(3).Name = "=""Unix"""

.HasTitle = False
.Axes(xlValue, xlPrimary).HasTitle = True
.Axes(xlValue, xlPrimary).AxisTitle.Characters.Text = "Ki
Numbers"
.HasAxis(xlCategory, xlPrimary) = True
.HasAxis(xlValue, xlPrimary) = True

.HasLegend = True
.ChartArea.AutoScaleFont = False
.SizeWithWindow = False
End With

If Not myChart.chart.SeriesCollection(1).Name = "Lan PCs" Then
myChart.chart.SeriesCollection(1).Delete
End If
If Not myChart.chart.SeriesCollection(2).Name = "Laptops" Then
myChart.chart.SeriesCollection(2).Delete
End If
If Not myChart.chart.SeriesCollection(3).Name = "Unix" Then
myChart.chart.SeriesCollection(3).Delete
End I
 
T

Tom Ogilvy

Nest the code that errors for this reason in

On Error Resume Next

' Just the code that works with the possibly non existent series
On Error goto 0
 

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