Hi, this may well be something basic that I'm missing, but I seem to be hitting my head against a brick wall. Any help would be gratefully appreciated!
I'm trying to run a basic model, the time step for the model is small (0.01), so I only want to display the data at a few key time points. The code seems to do this okay for small numbers (the initial time point is 1 and if I ask it to report m at t = 1.02 and t = 1.03 it will display the correct result in the requested cells) but not for anything much higher (I need it to report m at t = 1, 2, 3 ect up to 10, but if I ask it to report m at t = 2 and t = 3 nothing appears on the spreadsheet).
Private Sub CommandButton1_Click()
k = Cells(3, 2)
y = Cells(4, 2)
dt = Cells(6, 2)
im = Cells(9, 2) 'im is initial mass
it = Cells(10, 2) 'it is initial time
m = im
t = it
Do While t < 10
dmdt = k * Exp(-y * t) * m
dm = dmdt * dt
m = m + dm
t = t + dt
If t = 2 Then
mii = m
End If
Cells(13, 2) = mii
If t = 3 Then
miii = m
End If
Cells(14, 2) = miii
Loop
End Sub
If you need any more information, please let me know. Thanks in advance, Jo
Bookmarks