在excel vba 2016中运行循环以更改图表中的系列

我有以下的macros,我希望循环下面的程序500个图表从1开始。

Sub Arrow() ' ' Arrow Macro ' ' Keyboard Shortcut: Ctrl+q ' ActiveSheet.ChartObjects("Chart 459").Activate ActiveChart.FullSeriesCollection(1).Select With Selection.Format.Line .Visible = msoTrue .ForeColor.RGB = RGB(192, 0, 0) .Transparency = 0 End With With Selection.Format.Line .Visible = msoTrue .Weight = 2.5 End With Selection.Format.Line.EndArrowheadStyle = msoArrowheadTriangle With Selection.Format.Line .EndArrowheadLength = msoArrowheadLengthMedium .EndArrowheadWidth = msoArrowheadWide End With ActiveChart.FullSeriesCollection(2).Select With Selection.Format.Line .Visible = msoTrue .ForeColor.ObjectThemeColor = msoThemeColorAccent5 .ForeColor.TintAndShade = 0 .ForeColor.Brightness = -0.5 .Transparency = 0 End With With Selection.Format.Line .Visible = msoTrue .Weight = 2.5 End With Selection.Format.Line.EndArrowheadStyle = msoArrowheadTriangle With Selection.Format.Line .EndArrowheadLength = msoArrowheadLengthMedium .EndArrowheadWidth = msoArrowheadWide End With End Sub 

我同意@Jeeped。 你想要的并不难。 但是,从Select等移动到索引为基础需要一些学习。

下面的代码应该做你想要的。 它适用于Office 2010,它使用SeriesCollection(1)而不是FullSeriesCollection(1)

 Sub Arrow() ' ' Arrow Macro ' ' Keyboard Shortcut: Ctrl+q ' ActiveSheet.ChartObjects("Chart 459").Activate Dim i As Long Dim cht As Chart For i = 1 To ActiveWorkbook.Charts.Count Set cht = ActiveWorkbook.Charts(i) With cht.FullSeriesCollection(1).Format.Line .Visible = msoTrue .ForeColor.RGB = RGB(192, 0, 0) .Transparency = 0 .Weight = 2.5 .EndArrowheadStyle = msoArrowheadTriangle .EndArrowheadLength = msoArrowheadLengthMedium .EndArrowheadWidth = msoArrowheadWide End With With cht.FullSeriesCollection(2).Format.Line .Visible = msoTrue .ForeColor.ObjectThemeColor = msoThemeColorAccent5 .ForeColor.TintAndShade = 0 .ForeColor.Brightness = -0.5 .Transparency = 0 .Visible = msoTrue .Weight = 2.5 .EndArrowheadStyle = msoArrowheadTriangle .EndArrowheadLength = msoArrowheadLengthMedium .EndArrowheadWidth = msoArrowheadWide End With Next i End Sub 

现在你知道如何使用基于For循环和索引的引用。