下一个循环的运行时错误13不匹配

时间:2014-06-30 09:51:41

标签: excel-vba for-loop runtime next mismatch

Sub neeraj3()

Cells(5, 4).Value = Cells(10, 17).Value
Cells(4, 1).Value = 0
Cells(5, 1).Value = 1
Cells(4, 6).Value = Cells(1, 17).Value * 60000
Cells(5, 8).Value = Cells(5, 17).Value * 12
Dim c As Long
c = Cells(1, 10).Value * Cells(4, 6).Value
For i = 6 To Cells(1, 7).Value + 4
Cells(i, 4).Value = Cells(i - 1, 4).Value * (1 + Cells(11, 17).Value)
Cells(i, 1).Value = i - 4
Cells(i - 1, 6).Value = Cells(4, 6).Value - ((i - 5) * c)
Cells(i - 1, 7).Value = Cells(i - 1, 6).Value / (1 + Cells(1, 2).Value) ^ (i - 4)
Cells(i - 1, 5).Value = (Cells(i - 1, 4).Value / (1 + Cells(1, 2).Value) ^ (i - 5)) + Cells(i - 2, 5)
Cells(i, 8).Value = Cells(i - 1, 8).Value * (1 - Cells(13, 17).Value)
Cells(i - 1, 9).Value = Cells(i - 1, 8).Value / (1 + Cells(1, 2).Value) ^ (i - 5)
Cells(5, 10).Value = Cells(5, 9).Value
**Cells(i, 10).Value = Cells(i - 1, 10).Value + Cells(i, 9).Value**
Cells(i - 1, 11).Value = Cells(14, 17).Value / (1 + Cells(1, 2).Value) ^ (i - 5)
Cells(4, 12).Value = 0
Cells(i - 1, 12) = Cells(i - 2, 12).Value + Cells(i - 1, 11).Value
Cells(i - 1, 13).Value = (Cells(2, 17).Value + Cells(i - 1, 5).Value - Cells(i - 1, 12).Value - Cells(i - 1, 7).Value) / Cells(i - 1, 10).Value
Next i

For j = (Cells(1, 7).Value + 5) To 200
For k = 1 To 15
Cells(j, k).Value = "  "
Next k
Next j
For g = 5 To Cells(29, 17).Value + 4
Cells(g, 3).Value = Cells(30, 17).Value
Next g

End Sub

执行此循环时,我一直遇到运行时错误13不匹配。只有几次迭代后才会出现错误。我该怎么做才能使代码正确?

1 个答案:

答案 0 :(得分:0)

在循环中,最终您引用的其中一个单元格为空白(或某些文本)。你不能在数字和文本上使用+运算符,因此错误。

当代码错误时,调试器将以黄色显示该行。找出此时i的值(将鼠标悬停在它上面),这将告诉您它所指的是哪个单元格。