Editing Charts in VBA

GiraffetheGeek

Board Regular
Joined
May 25, 2011
Messages
58
Hi there,

I have a spreadsheet in which I have a graph.

At the moment the chart is only made up of for lines of data, but as time goes on this will increase.

I want the chart to update as time goes on so I have devised this peice of code to update the source data for the chart.

Code:
Sub FormatChart()
    
    Sheets("ChartData").Select
    Range("A1").Select
    If ActiveCell <> "" Then
        Do Until ActiveCell.Value = ""
        ActiveCell.Offset(0, 1).Select
        Loop
    End If
    ActiveCell.Offset(0, -1).Select
    endrow = ActiveCell.Row
    
    Sheets("Running Results").Select
    ActiveSheet.ChartObjects("Chart 8").Activate
    ActiveChart.ChartArea.Select
    ActiveChart.SeriesCollection(1).Values = "='ChartData'!$B$1:$B$" & endrow
    ActiveChart.SeriesCollection(2).Values = "='ChartData'!$E$1:$E$" & endrow
    ActiveChart.SeriesCollection(3).Values = "='ChartData'!$H$1:$H$" & endrow
    ActiveChart.SeriesCollection(4).Values = "='ChartData'!$K$1:$K$" & endrow
    ActiveChart.SeriesCollection(5).Values = "='ChartData'!$N$1:$N$" & endrow
    
End Sub

I get the error "Run-time error '1004' Unable to set the Values property of the Series class.

I sorta got out of my depth with this, but thought I might be able to teach myself something. Looks like not :(

Can anyone help?
 

Excel Facts

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.
Oops Sorry,

I thought I had posted already, but couldn't find my original post so I thought I must have not posted it.

My bad
 
Upvote 0

Forum statistics

Threads
1,224,521
Messages
6,179,285
Members
452,902
Latest member
Knuddeluff

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