PDA

View Full Version : Iteration Until Conditions Are Met - Need VBA Code



vtminer
02-21-2023, 01:31 PM
I'm new here and new to VBA coding. 99.999% of what I do in Excel doesn't require looping and iterations. But I have a unique issue here. I'll condense my problem for ease.

1.) Starting values are in Cells C2 through F2 for the "Values Range" below.
2.) "Values Range" are in Cells C5 through F10
3.) "Calculation Range" is in Cells C12 through F17
4.) The value in C5 corresponds to the value calculated in C12 and so on throughout both ranges.

What I need the code to do is as follows:

- Clear the values in C5 through F10
-Make all cells in C5 through F10 equal to the starting value at the top of each column (Cells C2 through F2)
-If after setting the cells in C5 to F10 to the starting value, the resulting values in the corresponding cells in C12 through F17 are greater than (>) 1.5, then the calculation for that cell stops. If the resulting value is less than 1.5, then the value in the appropriate cell in C5 through F10 is increased by 0.1. The function needs to continue looping/iterating by 0.1 until the 1.5 minimum is calculated.

Any help is greatly appreciated.

June7
02-21-2023, 02:02 PM
I develop new Excel VBA code with macro recorder. It always requires modification but it provides a starting point.

Attach a sample workbook with your data.

p45cal
02-22-2023, 02:56 PM
A guess.

Sub blah()
With Range("C5:F10")
.Value = Range("C2:F2").Value
For Each cll In .Cells
Do Until cll.Offset(7).Value > 1.5
cll.Value = cll.Value + 0.01
Loop
Next cll
End With
End Sub