【发布时间】:2017-01-02 09:58:11
【问题描述】:
所以我对 VBA 编码或一般编程非常陌生。我收到“编译错误:下一步没有 for”。我相信我会为 3 个 fors 提供 3 个下一个,但我仍然不知道。下面是我正在处理的代码......
Sub width2() '自动分配系列宽度
For Series = 1 To 24 'chart series, 144 combinations
For i = 0 To 1
For j = 0 To 11
ActiveSheet.ChartObjects("Chart 4").Activate
ActiveChart.FullSeriesCollection(Series).Select
With Selection.Format.Line
.Visible = msoTrue
.Weight = Sheet5.Range("Q9").Offset((9 * i) + 6, (3 * j)).Value
Next j
Next i
Next Series
End Sub
不确定错误在哪里。 非常感谢任何帮助 谢谢。
【问题讨论】:
-
你错过了
End With到你的With Selection.Format.Line -
With方法可能有问题。你没有关闭With。您必须在Next j之前使用End With。 -
在下一个 j 之前添加 end with 后,我现在得到:“找不到具有指定名称的项目”,行:ActiveSheet.ChartObjects("Chart 4").Activate
-
确保您的活动工作表中有一个名为
Chart 4的图表... -
@PiyushVerma 请使用
End With更新您的代码,以便我们从您的帖子中删除该错误。 Secod,您需要将您的ActiveSheet.ChartObjects("Chart 4").Activate和嵌套For循环中的以下行作为Sub的第一行。只需将.Weight = Sheet5.Range("Q9").Offset((9 * i) + 6, (3 * j)).Value保留在里面