I want to write a code that will copy a worksheet (Sheet2) x number of times and copy a differebt row of data from Sheet1 to each new copy.
For example: If I have data in rows 2 - 4 of Sheet1 I would want to copy Sheet2 three times and copy row 2 (Sheet1) to the first copy, copy row 3 (sheet1) to the second copy, and row 4 to the third copy.
The code i have to copy the sheets is below. But i don't know how to add the copy row feature.
Any help you could give you be appreciated. I can change what I have if there is a better way. I am very new to this, but I really want to learn how to use VBA.
Thanks,
For example: If I have data in rows 2 - 4 of Sheet1 I would want to copy Sheet2 three times and copy row 2 (Sheet1) to the first copy, copy row 3 (sheet1) to the second copy, and row 4 to the third copy.
The code i have to copy the sheets is below. But i don't know how to add the copy row feature.
Code:
Private Sub CommandButton1_Click()
Dim x As Integer
x = Range("A1").Value
For numtimes = 1 To x
'Loop by using x as the index number to make x number copies.
'Replace "Sheet1" with the name of the sheet to be copied.
ActiveWorkbook.Sheets("Sheet2").Copy _
After:=ActiveWorkbook.Sheets("Sheet2")
Next
End Sub
Any help you could give you be appreciated. I can change what I have if there is a better way. I am very new to this, but I really want to learn how to use VBA.
Thanks,