Compile Error While Setting Range for Chart Source Data

SBF12345

Well-known Member
Joined
Jul 26, 2014
Messages
614
Greetings,

I am receiving a compile error expected: = message after trying to set the source data range for an xyscatter chart type on the line below. I would like to use data ranges from another workbook "COMM_COMBINED.xls" and a worksheet by the worksheet variable name zz.

Code:
ch.SetSourceData (Workbooks("COMM_COMBINED.xls").Worksheets(zz).Range(Cells(3,b),Cells(yy,b)) , Workbooks("COMM_COMBINED.xls").Worksheets(zz).Range(Cells(3,a),Cells(yy,a)))

The above line exists within the context of the below script:

Code:
Set ch = Workbooks("COMM_Regress.xls").Worksheets(zz & "_C").Charts.Add

ch.Name = Workbooks("COMM_COMBINED.xls").Worksheet(zz).Cells(2, a).Value & Workbooks("COMM_COMBINED.xls").Worksheet(zz).Cells(2, b).Value
ch.ChartType = xlXYScatter
ch.SetSourceData (Workbooks("COMM_COMBINED.xls").Worksheets(zz).Range(Cells(3,b),Cells(yy,b)) , Workbooks("COMM_COMBINED.xls").Worksheets(zz).Range(Cells(3,a),Cells(yy,a)))


Thanks!
 

Excel Facts

Copy a format multiple times
Select a formatted range. Double-click the Format Painter (left side of Home tab). You can paste formatting multiple times. Esc to stop
I assume there is some number value for yy as well as a string value for zz? If zz is the name of a worksheet then use "zz" with quotes. Anyways, give this a trial...
Code:
Set ch = Workbooks("COMM_Regress.xls").Worksheets(zz).Charts.Add
ch.Name = Workbooks("COMM_COMBINED.xls").Worksheet(zz).Cells(2, "a").Value & Workbooks("COMM_COMBINED.xls").Worksheet(zz).Cells(2, "b").Value
ch.ChartType = xlXYScatter
ch.SetSourceData (Workbooks("COMM_COMBINED.xls").Worksheets(zz).Range(Cells(3,"A"),Cells(yy,"A")) , Workbooks("COMM_COMBINED.xls").Worksheets(zz).Range(Cells(3,"B"),Cells(yy,"B")))
HTH. Dave
 
Last edited:
Upvote 0
Also, do you want to say:

Code:
ch.SetSourceData Union(Workbooks("COMM_COMBINED.xls").Worksheets(zz).Range(Cells(3,"A"),Cells(yy,"A")) , Workbooks("COMM_COMBINED.xls").Worksheets(zz).Range(Cells(3,"B"),Cells(yy,"B")))
 
Upvote 0

Forum statistics

Threads
1,215,454
Messages
6,124,933
Members
449,195
Latest member
Stevenciu

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