Hello. I am a beginner in programming in vba excel and at the moment struggling with the following problem:
I have cell C5 value set as 5*B5+3. Now, using vba,I would like to adjust the value of B5 (basically find it), so that the value of C5 is let's say 8.
In this easy example, one can find rapidly the correct value of B5 to be 1.
What I've tried is the following code:
Private Sub CommandButton1_Click()
Range("B5").Value = -5
Do
Range("B5").Value = Range("B5").Value + 1
Loop Until Range("C5").Value = 8
End Sub
So, I am setting the initial guess for cell B5 and then increasing it by 1.
However, if I set the increment to 0.5 instead of 1, program goes crazy and loop doesn't close.
Could you please suggest what changes should I introduce to this code, so that even if the increment is 0.001 everything will work or maybe anyone could suggest a better approach to the problem?
Thank you in advance.
Bookmarks