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
--
Regards,
Tom Ogilvy
"lopsided " wrote in message
...
Hi,
I have a macro which creates new workbooks with charts on them. One of
these charts on each workbook has 3 series' on them, however, some of
these different workbooks have only got data for 1 or 2 of these
series'. When the code gets to where it shoudl rename the empty series
I get an error. If I try to then test to see if the name is what it
should be with an If statement it says - unable to get the name
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]Charges
Breakdown'!R3C3:R3C" & varIP + 2
SeriesCollection(1).Values = "='[Kit_Tracker.xls]Charges
Breakdown'!R" & varBreakdownRow & "C3:R" & varBreakdownRow & "C" &
varIP + 2
SeriesCollection(1).Name = "=""Lan PCs"""
SeriesCollection.NewSeries
SeriesCollection(2).XValues = "='[Kit_Tracker.xls]Charges
Breakdown'!R3C3:R3C" & varIP + 2
SeriesCollection(2).Values = "='[Kit_Tracker.xls]Charges
Breakdown'!R" & varBreakdownRow + 1 & "C3:R" & varBreakdownRow + 1 &
"C" & varIP + 2
SeriesCollection(2).Name = "=""Laptops"""
SeriesCollection.NewSeries
SeriesCollection(3).XValues = "='[Kit_Tracker.xls]Charges
Breakdown'!R3C3:R3C" & varIP + 2
SeriesCollection(3).Values = "='[Kit_Tracker.xls]Charges
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 = "Kit
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 If
---
Message posted from http://www.ExcelForum.com/