VBA Code to Resize a Chart

sbbarnett

New Member
Joined
May 24, 2018
Messages
3
I'm working with data that can be filtered multiple ways resulting in a variable number of rows of data. I also have a chart driven off of the data.

I want to create a macro that resizes the cahrt based on how many meaningful rows of data are present

I created the VBA code below where S27 contains the number of relevant rows. I want to substitute the row 85 below with the variable 'Counter' and I can't figure out a syntax that works.

Sub Macro1()
'
' Macro1 Macro
'
Counter = Range("S27").Value

ActiveSheet.ChartObjects("Chart 1").Activate
ActiveChart.PlotArea.Select
ActiveChart.SeriesCollection(1).Values = "='All Chart Data'!N27:N85"
ActiveChart.SeriesCollection(2).Values = "='All Chart Data'!O27:O85"
ActiveChart.SeriesCollection(3).Values = "='All Chart Data'!P27:P85"
ActiveChart.SeriesCollection(4).Values = "='All Chart Data'!Q27:Q85"
End Sub
 

Excel Facts

Create a Pivot Table on a Map
If your data has zip codes, postal codes, or city names, select the data and use Insert, 3D Map. (Found to right of chart icons).
Change
ActiveChart.SeriesCollection(1).Values = "='All Chart Data'!N27:N85"
to
ActiveChart.SeriesCollection(1).Values = "='All Chart Data'!N27:N" & range("S27").value

do the same for the other lines
 
Upvote 0
Change
ActiveChart.SeriesCollection(1).Values = "='All Chart Data'!N27:N85"
to
ActiveChart.SeriesCollection(1).Values = "='All Chart Data'!N27:N" & range("S27").value

do the same for the other lines

Thank you - I tried this but got: "Run Time Error '1004': Application-Defined or object-defines error" when it reached that step
 
Upvote 0

Forum statistics

Threads
1,223,903
Messages
6,175,287
Members
452,631
Latest member
a_potato

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