使用循环将每行数据的新系列添加到堆积柱形图

时间:2013-09-19 18:02:54

标签: excel vba excel-vba excel-2010

我正在尝试为我输入的每个新数据行添加新系列我想要系列的名称在B列中,值要在E到AH列中。从71-206循环的计数器和j变量考虑了标题和其他偏移,所以我将系列与其数据匹配。

非常感谢任何帮助。谢谢!

Sub stacked()
'
' stacked Macro
'
Dim i As Integer
Dim j As Integer

For i = 71 To 206
    ActiveChart.SeriesCollection.NewSeries
    j = i + 5
    ActiveChart.SeriesCollection(i).Name = "=Sheet1!B" & j
    ActiveChart.SeriesCollection(i).Values = "=Sheet1!E:AH" & j ":AH"&j
Next i

End Sub

1 个答案:

答案 0 :(得分:0)

Sub stacked()
'
' stacked Macro
'
Dim i As Integer
Dim j As Integer

For i = 71 To 206
ActiveChart.SeriesCollection.NewSeries
j = i + 5
ActiveChart.SeriesCollection(i).Name = "=Sheet1!B" & j
ActiveChart.SeriesCollection(i).Values = "=Sheet1!E" & j & ":AH" & j
Next i

End Sub

小错误,就是这样!