I am pretty much VBA ignorant. A kind gentelman helped me make a loop a few months back for a brewing spreadsheet that I made. The loop is fucntional, but I would like to modify it if possible. The loop is set up to make two cell values equal each other by adjusting the value of a third cell. To accomplish this 100% of the time, I had to set the loop to make adjustments in increments of .0001. The problem is, sometimes it can take quite a while for the computation to complete. If I set the loop to adjust in increments of .001, it is always able to get the two values in question within .01 of each other and the computations run a lot faster. For my purposes, a difference of .01 is insignificant. Is there a way to make the loop stop running when the two values get within .01 of each other istead of having to make them equal? Here is the coding I am working with.
Private Sub Worksheet_Change(ByVal Target As Range)
Dim dbQtsLb As Double
Application.EnableEvents = False
With Sheet1
If .Range("O17").Value = "Yes" And Sheet3.Range("G11").Value = "Equal" Then
Do While (.Range("Z29").Value <> .Range("Z30").Value)
If .Range("Z29").Value > .Range("Z30").Value Then
.Range("FO500") = .Range("FO500") - 0.0001
ElseIf .Range("Z29").Value < .Range("Z30").Value Then
.Range("FO500") = .Range("FO500") + 0.0001
End If
Loop
ElseIf Sheet3.Range("G11").Value = "Fixed" Or .Range("O17").Value = "No" Then
dbQtsLb = Format(Sheet3.Range("F12").Value, "#.0000")
Do While (.Range("Z27") <> dbQtsLb)
If .Range("Z27") > dbQtsLb Then
.Range("FO500") = .Range("FO500") - 0.0001
ElseIf .Range("Z27") < dbQtsLb Then
.Range("FO500") = .Range("FO500") + 0.0001
End If
Loop
End If
Application.EnableEvents = True
If Not Intersect(Target, .Range("B23:H23, A27:A29, H26:H31, A27:A29")) Is Nothing Then
UpdateMash1
End If
End With
End Sub
Bookmarks