ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Chart Identification Problems (https://www.excelbanter.com/excel-programming/290981-chart-identification-problems.html)

lopsided[_12_]

Chart Identification Problems
 
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

--
Message posted from http://www.ExcelForum.com


Tom Ogilvy

Chart Identification Problems
 
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/




lopsided[_13_]

Chart Identification Problems
 
Hi Tom

Thanks for your reply but im not sure I follow

--
Message posted from http://www.ExcelForum.com



All times are GMT +1. The time now is 07:49 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com