else 语句上的下标超出范围错误

Subscript out of range error on an else statement

提问人:Sidvi 提问时间:11/6/2017 最后编辑:CommunitySidvi 更新时间:11/7/2017 访问量:49

问:

当我尝试运行我的代码时,当它命中这段代码中的 else 语句时,我收到“下标超出范围”错误:

  If Cells(i + 4 - n, 9).Value > 0 Then
        Cells(i + 4 - n, 9).Interior.ColorIndex = RGB(93, 255, 132)
        Else
        Cells(i + 4 - n, 9).Interior.ColorIndex = RGB(255, 83, 83)
  End If

谁能告诉我如何解决这个问题?

Excel VBA

评论

0赞 Abhinav Rawat 11/6/2017
什么是 和 ?in
0赞 Sidvi 11/6/2017
只是 Excel 知道它在哪里的一种方式,我使用这些其他地方没有错误。
0赞 Abhinav Rawat 11/6/2017
是的,我也检查过...... 这个东西导致错误Interior.ColorIndex = RGB(93, 255, 132)
0赞 Sidvi 11/6/2017
现在它起作用了,是索引部分给我带来了问题。

答:

0赞 Abhinav Rawat 11/6/2017 #1

尝试-

If Cells(i + 4 - n, 9).Value > 0 Then
        Cells(i + 4 - n, 9).Interior.Color = RGB(93, 255, 132)
        Else
        Cells(i + 4 - n, 9).Interior.Color = RGB(255, 83, 83)
  End If