Copy & Paste Data a Specific Number of Times Question!

abl5037

New Member
Joined
Sep 28, 2011
Messages
1
Hello all,

I am relativly new to VBA, and I have spent a fair amount of time trying to figure out the following, however it appears that I am stuck!

The situation:

In one worksheet (sheet 1) I have a column of numbers
ex:

3
2
5

In another worksheet (sheet 2) I have a matrix of data that has the same number of rows as in sheet 1.
ex:

C678 2550 25 811 0
C563 2345 30 815 0
R456 5345 50 915 0

I am wanting to paste each row of sheet 2 into another sheet (sheet 3) X number of times (where X is equal to the corresponding value in sheet 1)
ex:

C678 2550 25 811 0
C678 2550 25 811 0
C678 2550 25 811 0
C563 2345 30 815 0
C563 2345 30 815 0
R456 5345 50 915 0
R456 5345 50 915 0
R456 5345 50 915 0
R456 5345 50 915 0
R456 5345 50 915 0


Can someone help me do this?! I have been trying and have not been able to get it to work at all! Thank you very much! If you need anymore information please let me know. Any help is greatly appreciated!

Thanks,

Austin
 

Excel Facts

How to total the visible cells?
From the first blank cell below a filtered data set, press Alt+=. Instead of SUM, you will get SUBTOTAL(9,)
Try this. I've assumed that the column of numbers on sheet 1 starts in cell A1. Change the code which refers to A, A1, etc., as appropriate if this isn't the case.
Code:
Sub Copy_Rows()

    Dim lastRow As Long
    Dim Sheet3Row As Long
    Dim cell As Range
    
    With Sheets("Sheet1")
        lastRow = .Cells(Rows.Count, "A").End(xlUp).Row
        Sheet3Row = 1
        For Each cell In .Range("A1:A" & lastRow)
            Sheets("Sheet2").Rows(cell.Row).Copy Sheets("Sheet3").Rows(Sheet3Row & ":" & Sheet3Row + cell.Value - 1)
            Sheet3Row = Sheet3Row + cell.Value
        Next
    End With
    
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,586
Messages
6,179,707
Members
452,939
Latest member
WCrawford

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