Do Loop Until [condition met], IF [condition met] THEN copy paste then repeat again VBA code

  • Good day,

    I have code that looks at the values generated from a random generator and once a condition is met then it stops. For example, it counts the numbers generated (for example 1, 2, 3) in range P1:P3 and once the condition value set in sheet1, A1 is met > 2, then it stops.


    I would like to go further by running more iterations. That is once condition is met in sheet 1, A1 then it copy and paste values sheet 1, P1:P3 into sheet2, A1:A3 then goes back to sheet 1 and re-runs the below code. I would like to do this 10 times. Each time condition is met then it copy and paste value into sheet2, in next available column, B1:B3 then C1:C3 until sheet2, J1:J3 is populated with a range then END. Is there a nested DO UNTIL LOOP, IF THEN to use? I have no clue and appreciate guidance.

    Code
    1. Do
    2. Sheet1.Range("A1").Formula = "=COUNTIF($P$1:$P$3,0)"
    3. Loop Until Sheet1.Range("A1").Value > 2
    4. End Sub
  • Possibly...

    If I've been helpful, let me know. If I haven't, let me know that too.

  • Hi, could I ask for further assistance with code? I am not sure if this is a new thread but it is meant to appendix the above code in my model.


    This will be a new sub routine.


    I have multiple columns of data (3 rows each) from columns M to column U or at least until there is an empty column range in sheet1. I want to copy and paste the first column data ( 3 rows) in column N and paste it to say sheet 1, cell C5 then my model runs until a condition is met and paste results in the next sheet2. Once that condition is met, then I want to get next column data (3 rows) from column N and paste over the data in cell C5 and the model runs until same condition is met again etc. This goes on until a blank column data is met in sheet1 then stops.


    If this is in violation of the forum rules please let me know, I'll understand. Thanks in advance.

  • Start a new thread and include a dummy workbook with what you started with and then the end result you're looking to achieve.

    If I've been helpful, let me know. If I haven't, let me know that too.