I have several charts in a workbook (one per worksheet) that report the last three weeks of data. The source data is non-contiguous columns in a ListObject table. Every week when the tables are updated with a new week of data (additional row) I want the charts to update.
This is similar to this post but I'm updating the series range instead of adding another series.
Here's some sample data:
A B C D E F
Start End Green Yellow Red Total
------- ------- ------- ------- ------- -------
1/1/16 1/7/16 10 10 10 30
1/8/16 1/14/16 12 12 12 36
1/15/16 1/21/16 12 20 18 50
1/22/16 1/28/16 30 10 50 45
The chart would first look like this:
Afterwards it would like like this: (disregard color difference)
Any suggestions on the easiest way to do this?
The Series formulas end up looking like this:
=SERIES(Project!$A$2,Project!$C$1:$E$1,Project!$C$2:$E$2,1)
=SERIES(Project!$A$3,Project!$C$1:$E$1,Project!$C$3:$E$3,2)
=SERIES(Project!$A$4,Project!$C$1:$E$1,Project!$C$4:$E$4,3)
I'm thinking of iterating through each Series in SeriesCollection, parsing out the different comma separated values, and updating the range. Something like this:
set clnSeries = activechart.seriescollection
dim strSeriesTemp as string 'Placeholder for previous series formula
For i = clnSeries.count to 1 step -1
if strSeriesTemp = "" then
strSeriesTemp = clnSeries(i).formula
arrSeries = split(clnSeries(i).formula, ",")
for i = lbound(arrSeries) to ubound(arrSeries)
select case i
'Move legend label one row down
case 1: strFormula = arrSeries(i).offset(1,0).address
'Leave series labels the same
case 2: strFormula = strFormula & arrSeries(i)
'Move series values one row down
case 3: strFormula = strFormula & arrSeries(i).offset(1,0).address
'Set series index
case 4: strFormula = strFormula & i
end select
strFormula = "=SERIES(" & strFormula & ")"
else
clnSeries(i).formula = strFormula
end if
next i