VBA Copying Set of Data n Times

elgre

New Member
Joined
Feb 18, 2022
Messages
13
Office Version
  1. 2016
Platform
  1. Windows
Hello everyone,

I have a question regarding copying set of data n times. I hope it is not too complicated and you could kindly help.

As I tried to illustrate an example with my perfectly artistic sketch, I want to copy the cells in column A to Column G for (lets say) 12 times, until data in column A finishes. Then I want to copy the set of data in column B (from AA to LL) to column H for each group (12times copied cells). I also tried to show it in the table below.

I would be really appreciated if you could show me the way to do this by using VBA.

Thank you very much for your help in advance.

Header1 - Data 1Header2 - Data 2Header 3Header4
AAAAAA
BBBABB
CCCACC
DDDADD
EEEAEE
FFFAFF
...GGAGG
HHAHH
IIAII
JJAJJ
KKAKK
LLALL
(no more data after LL)BAA
BBB
BCC
BDD
BEE
BFF
BGG
BHH
BII
BJJ
BKK
BLL
(continue until data finishes in Data1)(continue until data finishes in Data1)

1645193318010.png
 

Attachments

  • 1645193767629.png
    1645193767629.png
    40.9 KB · Views: 9

Excel Facts

How can you turn a range sideways?
Copy the range. Select a blank cell. Right-click, Paste Special, then choose Transpose.
Hi & welcome to MrExcel.
How about
VBA Code:
Sub elgre()
   Dim Rng As Range, Cl As Range
   
   Set Rng = Range("B2", Range("B" & Rows.count).End(xlUp))
   For Each Cl In Range("A2", Range("A" & Rows.count).End(xlUp))
      With Range("G" & Rows.count).End(xlUp).Resize(Rng.count)
         Cl.Copy .Offset(1)
         .Offset(1, 1).Value = Rng.Value
      End With
   Next Cl
End Sub
 
Upvote 0
That is amazing! Thanks a lot for your help, perfectly works!
 
Upvote 0
You're welcome & thanks for the feedback.
 
Upvote 0
Hi & welcome to MrExcel.
How about
VBA Code:
Sub elgre()
   Dim Rng As Range, Cl As Range
  
   Set Rng = Range("B2", Range("B" & Rows.count).End(xlUp))
   For Each Cl In Range("A2", Range("A" & Rows.count).End(xlUp))
      With Range("G" & Rows.count).End(xlUp).Resize(Rng.count)
         Cl.Copy .Offset(1)
         .Offset(1, 1).Value = Rng.Value
      End With
   Next Cl
End Sub
Hello everyone, how I can change this VBA to copy two columns instead of one? Lets say the B column is actually C column and there is one extra column - for the purpose of explanation I will add one more column before A. Now - both columns are with the same number of rows (A and B) instead of the one column which is in the example above. I need to copy both of them. I tried to change the macro but without success. Your help is greatly appreciated.
 
Upvote 0
As your question is significantly different from the op, please start a thread of your own. Thanks
 
Upvote 0

Forum statistics

Threads
1,223,950
Messages
6,175,582
Members
452,653
Latest member
craigje92

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