VB Code - loop a copy and paste a specified number of times

santa12345

Board Regular
Joined
Dec 2, 2020
Messages
70
Office Version
  1. 365
Platform
  1. Windows
Hello.
I have a simple worksheet for an example...

1622661266287.png

I want to populate R2:R6 with audi, then copy R7:R11 with benz, etc...
The real dataset I have in Column S is 100's of rows, but if I can get code using the above, I'll modify it as needed.
So copy Audi to column R..starting in R2 for a specified number of times, in this case, 5 times, then loop to do the same for the values in v3 - v6.. loop until done.


I can build out column S as needed... no need to have that in the code.
Hopefully this makes sense. If not - please let me know.
Thank you.
 

Excel Facts

What does custom number format of ;;; mean?
Three semi-colons will hide the value in the cell. Although most people use white font instead.
How about
VBA Code:
Sub santa()
   Dim Rng As Range, Cl As Range
   Dim NxtRw As Long
   
   NxtRw = 2
   Set Rng = Range("S2", Range("S" & Rows.Count).End(xlUp))
   For Each Cl In Range("V2", Range("V" & Rows.Count).End(xlUp))
      Cl.Copy Range("R" & NxtRw).Resize(Rng.Count)
      NxtRw = NxtRw + Rng.Count
   Next Cl
End Sub
 
Upvote 0
Hello and thank you for replying.
I'm getting the following error.

1622662811131.png


ON LINE the C1.copy Range line...

I did change the columns letters... as needed to fit my template.
 
Upvote 0
Nevermind.. I have no clue what I'm doing.
The code you provided works great !!!
Thank you.. this will save me hours of copying and pasting data.
Thanks again and have a good day!
 
Upvote 0
You're welcome & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,223,961
Messages
6,175,652
Members
452,664
Latest member
alpserbetli

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
Back
Top