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
 

Excel Facts

Excel Can Read to You
Customize Quick Access Toolbar. From All Commands, add Speak Cells or Speak Cells on Enter to QAT. Select cells. Press Speak Cells.
I am new in vba.

In order to process things in a chart shouldn't I activate everytime the
relevant chart ?

If this is correct, then the first activated chart in the code is the "Problematic". So after the processing of this chart, I must activate the "Problematic_10" in order to make the changes in this chart.

Is this not necessary ? Is there another alternative ?

And even if this is not necessary, why this error ?

Thanks,

Tzovanis
 
Upvote 0
No it's not necessary because you have:

With ActiveSheet.ChartObjects("Problematic_10")

Sorry, I don't know the cause of the error.
 
Upvote 0
Hi,

I deleted the line
Code:
ActiveSheet.ChartObjects("Problematic_10").Activate

and still the same error.

Run-time error "1004"
 
Upvote 0
Hi Kotzo

The error seems to say that there is no chartobject named "Problematic_10".

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

Code:
      .Name = icolumn

After the code runs, and stops at the error, go to the worksheet and check the name of the second chartobject.
 
Upvote 0
Hi pgc01,


It worked !!!

I thank you and Andrew Poulsom for your help and support !!!

Tzovanis
 
Upvote 0

Forum statistics

Threads
1,215,351
Messages
6,124,445
Members
449,160
Latest member
nikijon

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