Repeating same range of data

Akakumori

New Member
Joined
Jun 10, 2017
Messages
25
Hello,
How can I dos this?
I want to repeat a range of data which contains 3 colums and 70 rows 20 times.
First colum contains a reference number, same for all 70 rows, second column a vale which doesn't change and third colum the name of 70 different countries.
I want this range to repeat again below by just changing the reference number in the first row for another value I have listed un sheet2.
As many repetitions as references numbers I have un the list of sheet2.

Can someone help me? The task is huge when I have to paste same range like 20 or 50 times when there are lots of references.

Thanks!
 
Last edited:

Excel Facts

Last used cell?
Press Ctrl+End to move to what Excel thinks is the last used cell.
You can put some examples of what you have in the 2 sheets and the expected result.
 
Upvote 0
Sheet1:

ColumnA/ColumnB/ColumnC
3564/666/France
3564/666/Italy
3564/666/Spain
....

Sheet 2:
ColumnA
3564
6437
7544
....

Hi
Let me know if it is understandable.
Thanks
 
Upvote 0
Expected result:
ColumnA/ColumnB/ColumnC
3564/666/France
3564/666/Italy
3564/666/Spain
6437/666/France
6437/666/Italy
6437/666/Spain
7544/666/France
7544/666/Italy
7544/666/Spain

In same sheet1 or just un a new sheet, It doesn't matter.

Thanks
 
Upvote 0
Try this, change sheets 1,2 y 3 for the names of yours sheets.

Code:
Sub Repeating_range()
  Dim sh1 As Worksheet, sh2 As Worksheet, sh3 As Worksheet
  Dim i As Long, lr1 As Long, lr3 As Long
  Set sh1 = Sheets("[COLOR=#0000ff]Sheet1[/COLOR]")
  Set sh2 = Sheets("[COLOR=#0000ff]Sheet2[/COLOR]")
  Set sh3 = Sheets("[COLOR=#0000ff]Sheet3[/COLOR]")
  Application.ScreenUpdating = False
  sh3.Cells.ClearContents
  lr1 = sh1.Range("A" & Rows.Count).End(xlUp).Row
  For i = 1 To sh2.Range("A" & Rows.Count).End(xlUp).Row
    sh1.Range("A1:C" & sh1.Range("A" & Rows.Count).End(xlUp).Row).Copy
    lr3 = sh3.Range("A" & Rows.Count).End(xlUp).Row
    sh3.Range("A" & lr3 + 1).PasteSpecial xlPasteAll
    sh3.Range("A" & lr3 + 1).Resize(lr1).Value = sh2.Range("A" & i)
  Next
  MsgBox "Done"
End Sub
 
Upvote 0
Hello,
I would like yo do a variation to this Macro and my source data will look like this:

sheet1:
ColumnA/ColumnB/ColumnC
1234/123/456
675/145/123
34/13/46
1346/567/678

Sheet2:
ColumnA
France
Japan
Greece

Expected result on sheet3:

Repeat data we have on sheet1 as many times as countries we have on sheet2:
ColumnA/ColumnB/ColumnC/ColumnD

1234/123/456/France
675/145/123/France
34/13/46/France
1346/567/678/France
1234/123/456/Japan
675/145/123/Japan
34/13/46/Japan
1346/567/678/Japan
....

In some cases ColumnC in sheet1 may be empty. In this case I want to keep it empty also in the final result in sheet3.

Thanks
 
Upvote 0
Hello, any ideas how should I transform Macro provided by @DanteAmor in order to do this variation?
I have tried but my knowledge is limited and I can find a solution.

Thanks
 
Upvote 0
Try this

VBA Code:
Sub Repeating_range()
  Dim sh1 As Worksheet, c As Range, lr1 As Long, lr3 As Long
  Set sh1 = Sheets("Sheet1")
  With Sheets("Sheet3")
    .Cells.ClearContents
    lr1 = sh1.Range("A" & Rows.Count).End(xlUp).Row
    For Each c In Sheets("Sheet2").Range("A1", Sheets("Sheet2").Range("A" & Rows.Count).End(xlUp))
      lr3 = .Range("A" & Rows.Count).End(xlUp).Row + 1
      .Range("A" & lr3).Resize(lr1, 3).Value = sh1.Range("A1:C" & lr1).Value
      .Range("D" & lr3).Resize(lr1).Value = c.Value
    Next
  End With
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,703
Messages
6,173,977
Members
452,540
Latest member
haasro02

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