IF [condition met] THEN copy paste then repeat again VBA code

Status
Not open for further replies.

RRM

New Member
Joined
Mar 10, 2020
Messages
5
Office Version
  1. 2013
Platform
  1. Windows
  2. MacOS
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.

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

Some videos you may like

Excel Facts

Remove leading & trailing spaces
Save as CSV to remove all leading and trailing spaces. It is faster than using TRIM().

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
55,253
Office Version
  1. 365
Platform
  1. Windows
Duplicate copy and paste values with offset in columns vba code

Please do not post the same question multiple times. All clarifications, follow-ups, and bumps should be posted back to the original thread. Especially considering you had a reply which you seem to have ignored.
Per forum rules, posts of a duplicate nature will be locked or deleted (rule 12 here: Forum Rules).
 
Status
Not open for further replies.

Watch MrExcel Video

Forum statistics

Threads
1,127,009
Messages
5,622,145
Members
415,881
Latest member
tasic89

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top