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

时间:2017-11-06 12:37:23

标签: excel excel-vba vba

当我尝试运行我的代码时,我得到一个"下标超出范围"当它碰到这段代码中的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

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

1 个答案:

答案 0 :(得分:0)

尝试 -

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