Problem When Creating A Multiple Series Chart

kotzo

Board Regular
Joined
Aug 1, 2010
Messages
119
Hi,

The following code creates 2 charts ("Problematic" and "Problematic_10")
in the worksheet "Problematic Stock" of the workbook "Reports_1"

Everything work for the first chart. The problem starts with the command
Code:
ActiveSheet.ChartObjects("Problematic_10").Activate

Run-time error "1004"

(see bold command in code bellow)

I want to mention that the same command some lines above for the chart "Problematic" works perfectly

Code:
[SIZE=1]  ' *************************************************************************************************
  '                                             CREATION OF SUM CHART
 ' **************************************************************************************************
  Workbooks.Open "C:\Logistics Container\Reports_1.xls"
    Workbooks("Reports_1.xls").Activate
  Worksheets("Problematic Stock").Activate
Set Sh = Workbooks(backbone).Sheets("Data_Discont")[/SIZE]
[SIZE=1]If inde <= 1 Then
   With ActiveSheet.ChartObjects.Add(Left:=25, Width:=375, Top:=50, Height:=225)
      .Name = "Problematic"
      .Chart.ChartType = xlLineMarkers
      .Chart.SeriesCollection.NewSeries
       .Chart.SeriesCollection(1).XValues = "=[" & backbone & "]Data_Discont!" & Sh.Range(Sh.Cells(4, 1), Sh.Cells(inde + 3, 1)).Address(, , xlR1C1)
        .Chart.SeriesCollection(1).Values = "=[" & backbone & "]Data_Discont!" & Sh.Range(Sh.Cells(4, 12), Sh.Cells(inde + 3, 12)).Address(, , xlR1C1)
      .Chart.HasTitle = True
       .Chart.HasLegend = False
       .Chart.ChartTitle.Text = "Discontinued Products - Sum"
      .Chart.Axes(xlCategory, xlPrimary).HasTitle = False
      .Chart.Axes(xlValue, xlPrimary).HasTitle = True
      .Chart.Axes(xlValue, xlPrimary).AxisTitle.Characters.Text = "Áîßá"[/SIZE]
[SIZE=1]    GoTo 9993
   End With
  
End If[/SIZE]
[SIZE=1]9993
 
ActiveSheet.ChartObjects("Problematic").Activate
 With ActiveSheet.ChartObjects("Problematic")
        .Chart.SeriesCollection(1).XValues = "=[" & backbone & "]Data_Discont!" & Sh.Range(Sh.Cells(4, 1), Sh.Cells(inde + 3, 1)).Address(, , xlR1C1)
        .Chart.SeriesCollection(1).Values = "=[" & backbone & "]Data_Discont!" & Sh.Range(Sh.Cells(4, 12), Sh.Cells(inde + 3, 12)).Address(, , xlR1C1)[/SIZE]
[SIZE=1]   End With[/SIZE]

[SIZE=1]  ' *************************************************************************************************
  '                                             CREATION OF "PER PRODUCT" CHART
 ' **************************************************************************************************[/SIZE]
[SIZE=1]If inde <= 1 Then
   With ActiveSheet.ChartObjects.Add(Left:=25, Width:=375, Top:=300, Height:=225)
      .Name = "Problematic_10"
      .Chart.ChartType = xlLineMarkers
      .Chart.SeriesCollection.NewSeries
      
      For icolumn = 1 To 1
      .Chart.SeriesCollection(icolumn).XValues = "=[" & backbone & "]Data_Discont!" & Sh.Range(Sh.Cells(4, 1), Sh.Cells(inde + 3, 1)).Address(, , xlR1C1)
      .Chart.SeriesCollection(icolumn).Values = "=[" & backbone & "]Data_Discont!" & Sh.Range(Sh.Cells(4, 2), Sh.Cells(inde + 3, 11)).Address(, , xlR1C1)
      .Name = icolumn
      Next
      
      .Chart.HasTitle = True
       .Chart.HasLegend = True
       .Chart.ChartTitle.Text = "Discontinued Products / Per Product"
      .Chart.Axes(xlCategory, xlPrimary).HasTitle = False
      .Chart.Axes(xlValue, xlPrimary).HasTitle = True
      .Chart.Axes(xlValue, xlPrimary).AxisTitle.Characters.Text = "Áîßá"
'
    GoTo 99931
   End With
  
End If[/SIZE]
[SIZE=1]99931
 
If inde <= 1 Then GoTo 44333[/SIZE]
[SIZE=1][B]ActiveSheet.ChartObjects("Problematic_10").Activate[/B]
 With ActiveSheet.ChartObjects("Problematic_10")
     
For icolumn = 1 To 10
        .Chart.SeriesCollection(icolumn).XValues = "=[" & backbone & "]Data_Discont!" & Sh.Range(Sh.Cells(4, 1), Sh.Cells(inde + 3, 1)).Address(, , xlR1C1)[/SIZE]
[SIZE=1]        .Chart.SeriesCollection(icolumn).Values = "=[" & backbone & "]Data_Discont!" & Sh.Range(Sh.Cells(4, icolumn + 1), Sh.Cells(inde + 3, 12)).Address(, , xlR1C1)
Next icolumn
44333
   End With[/SIZE]


Thank yoy for your help,

Tzovanis
 
In fact, looking at your code, it seems you are changing the name of the second chart when you add the series

Pedro, you have eyes like a hawk! :eek: I imagine kotzo wanted to name the Series:

Code:
.Chart.SeriesCollection(icolumn).Name = icolumn
 
Upvote 0

Excel Facts

Why are there 1,048,576 rows in Excel?
The Excel team increased the size of the grid in 2007. There are 2^20 rows and 2^14 columns for a total of 17 billion cells.

Forum statistics

Threads
1,216,124
Messages
6,128,993
Members
449,480
Latest member
yesitisasport

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top