宏运行时错误' 9':下标超出宏范围

时间:2017-06-15 08:50:35

标签: excel-vba vba excel

我正在用VBA编写一个宏。如果你在Excel中按下一个按钮,它将超出代码。下面是代码的第一部分。如果我执行程序,那么我得到运行时错误9,下标超出范围。我该如何解决这个错误?该错误指向ReDim rij(1 To z) As Integer

ThisWorkbook.Sheets("InvoerIO").Range("O1") = z

ReDim rij(1 To z) As Integer  

For r = 1 To ThisWorkbook.Sheets("InvoerIO").Range("O1")         
    If r > 7 Then
        z = ThisWorkbook.Sheets("InvoerIO").Range("O1")
        rij(r) = rij(r - 1)    
        If Sheets("InvoerIO").Cells(r, 3).value = "part1" Then        
            rij(r) = 90

等。

1 个答案:

答案 0 :(得分:0)

更改

ThisWorkbook.Sheets("InvoerIO").Range("O1") = z

z = ThisWorkbook.Sheets("InvoerIO").Range("O1").Value