very novice user, having some difficulty getting this code up and running. I am attempting to calculate a value based on some other cells and iterating to minimize error. When running, I get the aforementioned error on the Cells(i, 17) = Cells(i, 5) line. Thoughts? Thank you.
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)
? Set the value in the cellCells(i,17)
equal to the value currently inCells(i, 5)
? Also what is theFor Loop
doing? Right now it is going through the entire loop before getting to your iter variable, so the results of your for loop are going to be exactly the same each time. – tittaenälg