How to pass an Array to a Chart using VBA

Juggler_IN

Active Member
Joined
Nov 19, 2014
Messages
358
Office Version
  1. 2003 or older
Platform
  1. Windows
I have a Chart with 10 Series. For one of the series (Series 9) I want to pass the values using an array.

I have created a SUB but I am unable to execute it, and can't figure out the reason.

There are two charts in the Sheet. Chart1 and Chart2. I want to pass values to Chart1.

Error that I am getting is, Method 'SeriesCollection' of 'Object '_Chart' failed.

Code:
Sub VBAchrt()

Dim myChart As Chart


Dim xlist As Variant, ylist As Variant, n As Long, i As Long
n = 1000
ReDim xlist(1 To n), ylist(1 To n)

For i = 1 To n
xlist(i) = Range("B" & i + 3).Value
ylist(i) = 1
Next i

Set myChart = ActiveSheet.ChartObjects(1).Chart
myChart.SeriesCollection(9).XValues = xlist
myChart.SeriesCollection(9).Values = ylist


End Sub
 

Excel Facts

How to create a cell-sized chart?
Tiny charts, called Sparklines, were added to Excel 2010. Look for Sparklines on the Insert tab.

Forum statistics

Threads
1,223,098
Messages
6,170,099
Members
452,301
Latest member
QualityAssurance

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