Consulting

Results 1 to 3 of 3

Thread: Iteration Until Conditions Are Met - Need VBA Code

  1. #1
    VBAX Newbie
    Joined
    Feb 2023
    Posts
    1
    Location

    Iteration Until Conditions Are Met - Need VBA Code

    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.

  2. #2
    VBAX Mentor
    Joined
    Nov 2022
    Location
    The Great Land
    Posts
    337
    Location
    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.
    How to attach file: Reading and Posting Messages (vbaexpress.com), click Go Advanced below post edit window. To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    Knowledge Base Approver VBAX Wizard p45cal's Avatar
    Joined
    Oct 2005
    Location
    Surrey UK
    Posts
    5,875
    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
    p45cal
    Everyone: If I've helped and you can't be bothered to acknowledge it, I can't be bothered to look at further posts from you.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •