Monday, August 18, 2008

Updating chart series's source

The following VB script code is a simple example on how to modify the data source of a series using array. Let's say you have already created a chart in a sheet which its name is "Sheet1".

Dim srs As Series
Dim yval() As String
Dim xval() As Integer

Set srs = Sheets("Sheet1").ChartObjects(1).Chart.SeriesCollection(1)
Dim v As Integer

v = 6
ReDim yval(0 To v - 1)
ReDim xval(0 To v - 1)
yval(0) = "MINE"
yval(1) = "LOG"
yval(2) = "EXR"
yval(3) = "SES"
yval(4) = "PP"
yval(5) = "UT"

xval(0) = 2
xval(1) = 1
xval(2) = 1
xval(3) = 2
xval(4) = 1
xval(5) = 1

srs.XValues = yval
srs.Values = xval

No comments: