【发布时间】:2016-09-02 22:45:14
【问题描述】:
非常新手用户,在启动和运行此代码时遇到了一些困难。我正在尝试根据其他一些单元格计算一个值并进行迭代以最小化错误。运行时,我在 Cells(i, 17) = Cells(i, 5) 行上收到上述错误。想法?谢谢。
Private Sub CommandButton1_Click()
Dim i As Long
A = 6.112
B = 17.67
C = 243.5
epsilon = 0.622
G = B * C
maxerror = 0.001
For i = 2 To Rows.Count
Next i
iter = 0
Cells(i, 17) = Cells(i, 5)
Do While iter < 50
iter = iter + 1
bt = B * Cells(i, 17)
tpc = Cells(i, 17) + C
d = (Cells(i, 9) / A) * Exp(-bt / tpc)
dm1 = d - 1#
f = (Cells(i, 5) - Cells(i, 17)) - Cells(i, 16) * (epsilon / dm1 - Cells(i, 13))
df = -G / (tpc * tpc)
df = d * df * Cells(i, 16) * epsilon / (dm1 * dm1) - 1#
cor = f / df
Cells(i, 17) = Cells(i, 5) - cor
If Abs(cor) < maxerror Then
Exit Do
End If
Loop
End Sub
【问题讨论】:
-
设置
Cells(i, 17) = Cells(i, 5)时你想做什么?将单元格Cells(i,17)中的值设置为等于Cells(i, 5)中的当前值?还有For Loop在做什么?现在它在到达你的 iter 变量之前要经过整个循环,所以你的 for 循环的结果每次都会完全一样。
标签: excel vba runtime-error