Creating a chart with "Union"

kotzo

Board Regular
Joined
Aug 1, 2010
Messages
119
Hi,

I want to create a chart in a specific sheet ("Problematic Stock") of a workbook ("Reports_1.xls"). I take the data from the workbook ( backbone = "Data_Backbone.xls") from the sheet "Problematic Stock".

I use the following code:
Code:
  [SIZE=1]Workbooks.Open "C:\Logistics Container\Reports_1.xls"
    Workbooks("Reports_1.xls").Activate
  Worksheets("Problematic Stock").Activate[/SIZE]
[SIZE=1]   With Charts.Add
      .Name = "Test"
      .ChartType = xlColumnClustered
    [B]  .SetSourceData Source:=Workbooks(backbone).Sheet("Data_Discont").Union(range(cells(4, 1), cells(inde + 3, 1)), range(cells(4, 12), cells(inde + 3, 12))), PlotBy:=xlRows
[/B]      .HasTitle = True
      .ChartTitle.Text = "=Problematic Stock!R1C2"
      .Axes(xlCategory, xlPrimary).HasTitle = True
      .Axes(xlCategory, xlPrimary).AxisTitle.Characters.Text = "Month"
      .Axes(xlValue, xlPrimary).HasTitle = True
      .Axes(xlValue, xlPrimary).AxisTitle.Characters.Text = "Sales"
   End With[/SIZE]

Error: 438 (at the bold line).

Could you please help me ?

Thanks,

Tzovanis
 
This worked for me:

Code:
Sub Test()
    Const inde As Integer = 10
    Dim backbone As String
    Dim Sh As Worksheet
    backbone = "Data_Backbone.xls"
    Set Sh = Workbooks("Data_Backbone.xls").Worksheets("Data_Discont")
    With Charts.Add
        .SeriesCollection.NewSeries
        .SeriesCollection(1).XValues = "=[" & backbone & "]Data_Discont!" & Sh.Range(Sh.Cells(4, 1), Sh.Cells(inde + 3, 1)).Address(, , xlR1C1)
        .SeriesCollection(1).Values = "=[" & backbone & "]Data_Discont!" & Sh.Range(Sh.Cells(4, 12), Sh.Cells(inde + 3, 12)).Address(, , xlR1C1)
    End With
End Sub
 
Upvote 0

Excel Facts

Can Excel fill bagel flavors?
You can teach Excel a new custom list. Type the list in cells, File, Options, Advanced, Edit Custom Lists, Import, OK
Hi,

It worked !!!!!!!!!!!!!!!!

Thank you very much for your support !!!!

Could you please explain to me why ????


Many thanks again,

Tzovanis
 
Upvote 0
The key is:

Rich (BB code):
.SeriesCollection.NewSeries

But there was also a misplaced parenthesis in the code I originally gave you. Compare the 2 lines below:

Rich (BB code):
.SeriesCollection(1).XValues = "=[" & backbone & "]Data_Discont!" & Sh.Range(Sh.Cells(4, 1), Sh.Cells(inde + 3, 1).Address(, , xlR1C1))

.SeriesCollection(1).XValues = "=[" & backbone & "]Data_Discont!" & Sh.Range(Sh.Cells(4, 1), Sh.Cells(inde + 3, 1)).Address(, , xlR1C1)
 
Upvote 0

Forum statistics

Threads
1,216,091
Messages
6,128,775
Members
449,468
Latest member
AGreen17

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