Extend plotting range in VBA

Olibrius

New Member
Joined
May 23, 2015
Messages
9
Hi everybody,
I have a large worksheet with data (always increasing), and I have a lot of graphic sheets each containing a scatter plot of a part of these data. Thus, in these sheets, there is a graphic defined by:
=SERIES(data!$B$1,data!$A$2:$A$1350,data!$B$2:$B$1350,1) for the first sheet,
=SERIES(data!$C$1,data!$A$2:$A$1350,data!$C$2:$C$1350,1) for the second,
=SERIES(data!$D$1,data!$A$2:$A$1350,data!$D$2:$D$1350,1) and so on.
When my data range becomes larger, I have to change $1350 to, say, $1400 in every and each of the charts. And still worse, I have to do it by hand, because search and replace doesn't work on graphics!
That's the reason why I'm looking for a VBA macro I could apply on each graphic sheet to update its range.
If somebody could help me, I'd really appreciate.
Thank you.
O.
 

Excel Facts

Shade all formula cells
To shade all formula cells: Home, Find & Select, Formulas to select all formulas. Then apply a light fill color.
You would need to create a chart object varfiable to represent the chart you want to work with. eg. myChart = Sheet1.ChartObjects(1).Chart, or some similar assignment of the object.
Then
Code:
Dim myChart As Chart, Ser As Double
Set myChart = Sheets("Sheet1").ChartObjects(1).Chart
Ser = $1400
myChart.SeriesCollection.Extend Worksheets(1).Range(Ser)
The number in parentheses represents the index number of the chart object, so if you have more than one to a sheet, that index number will vary according to which chart you want to work with. If you have three charts, you could
Code:
For i = 1 To 3
	Set myChart = Sheets("Sheet1").ChartObjects(i).Chart
	Ser = $1400 'If this value varies per chart then an array would be needed to feed this value as a variable.
	myChart.SeriesCollection.Extend Worksheets(1).Range(Ser)
Next
 
Last edited:
Upvote 0
Solution
You would need to create a chart object variable to represent the chart you want to work with. eg. myChart = Sheet1.ChartObjects(1).Chart, or some similar assignment of the object.
Then [...]
myChart.SeriesCollection.Extend Worksheets(1).Range(Ser)
[...]
Wahoo That's exactly what I needed! I just didn't know how to manipulate the charts in VBA...
Thanks a lot JLGWiz!
 
Upvote 0
The sample I posted is misleading. I copied from some old code of mine and forgot to make the adjustment.
If you are using acual values you would not use the Range(ser) syntax. Use just the ser variable. The Range() is only used when the series is comprised of a range of cell values.
Code:
myChart.SeriesCollection.Extend Worksheets(1).Ser
 
Upvote 0
Thanks for the update! It'll certainly spare me some head scratching... ;)

I didn't do a very good job of updating either.
Code:
Set myChart = Sheets("Sheet1").ChartObjects(1).Chart
Ser = $1400
myChart.SeriesCollection.Extend Ser

This is the correct syntax when only adding a value and not a range containing a value.
 
Upvote 0
Ah, VBA syntax... What an endless source of fun!:oops: I believe it's the real root of the trial and error method:ROFLMAO:
 
Upvote 0

Forum statistics

Threads
1,215,036
Messages
6,122,794
Members
449,095
Latest member
m_smith_solihull

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