VBA Modify Chart .FullSeriesCollection() - Optimize Code

bs0d

Well-known Member
Joined
Dec 29, 2006
Messages
622
I'm using VBA to re-reference the max row reference for series on a chart in my 2013 Excel workbook.

This code works:
Code:
    Sheets("DASHBOARD").ChartObjects("Hist").Activate
    ActiveChart.ChartArea.Select
    ActiveChart.FullSeriesCollection(1).Values = "=Data!$H$2:$H$" & FinalRow
    ActiveChart.FullSeriesCollection(2).Values = "=Data!$I$2:$I$" & FinalRow
    ActiveChart.FullSeriesCollection(3).Values = "=Data!$J$2:$J$" & FinalRow
    ActiveChart.FullSeriesCollection(4).Values = "=Data!$K$2:$K$" & FinalRow
However, If possible, I don't want to activate and select the chart through the process. Here is my stab at it, which yields an error:
Code:
    With Sheets("DASHBOARD").ChartObjects("Hist").ChartArea
        .FullSeriesCollection(1).Values = "=Data!$H$2:$H$" & FinalRow
        .FullSeriesCollection(2).Values = "=Data!$I$2:$I$" & FinalRow
        .FullSeriesCollection(3).Values = "=Data!$J$2:$J$" & FinalRow
        .FullSeriesCollection(4).Values = "=Data!$K$2:$K$" & FinalRow
   End With
Is it possible to modify the chart series as I'm attempting without actually selecting the chart? If so, I'd like to see how. Thanks,
 

Excel Facts

Whats the difference between CONCAT and CONCATENATE?
The newer CONCAT function can reference a range of cells. =CONCATENATE(A1,A2,A3,A4,A5) becomes =CONCAT(A1:A5)
Any thoughts? Why wouldn't WITH work here? Is it possible to avoid activating the chart? I'd like to avoid activating it which brings the chart to focus in the workbook after the code executes.

Thanks
 
Upvote 0
I think I found the solution. adding ".chart" after .ChartObjects() seems to do the trick.

Code:
    With Sheets("DASHBOARD").ChartObjects("Hist").Chart.ChartArea
        .FullSeriesCollection(1).Values = "=Data!$H$2:$H$" & FinalRow
        .FullSeriesCollection(2).Values = "=Data!$I$2:$I$" & FinalRow
        .FullSeriesCollection(3).Values = "=Data!$J$2:$J$" & FinalRow
        .FullSeriesCollection(4).Values = "=Data!$K$2:$K$" & FinalRow
   End With
 
Upvote 0

Forum statistics

Threads
1,223,164
Messages
6,170,444
Members
452,326
Latest member
johnshaji

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