PDA

View Full Version : Macro to Copy only 10 rows per worksheet



honeydew
10-12-2008, 01:39 AM
The below macro copies certain cell contents from multiple worksheets to another workbook's first sheet.
Can you help me in modifying the below Macro in such a way, that on a click of a button,it should copy the specified contents and paste only 10 rows per sheet into another workbook. ( now it copies and pastes in single sheet) It should be modified as detailed below

i.e.,


The 1st to 10th row should be pasted automatically in the next new worksheet
11th to 20th row should be pasted automatically in the next new worksheet,
21st to 30th row should be pasted automatically in the next new worksheet,
it should be keep going as such.
Moreover, upon completion of pasting every 10 rows, new worksheets should be added automatically in Master.xls for copying of rest of the rows.

(The cell contents from which it should be copied and the cells to which it should be pasted should be as per the below macro).

Sub COPY_TO_DISTRIBUTOR()
Windows("DISTRIBUTOR.xls").Activate
For MY_SHEETS = 2 To ActiveWorkbook.Sheets.Count
With Sheets(MY_SHEETS)
.Range("B2").Copy
Workbooks("Master.xls").Activate
Range("B" & MY_SHEETS + 2).PasteSpecial (xlPasteAll)
.Range("P18:S18").Copy
Range("C" & MY_SHEETS + 2).PasteSpecial (xlValues)
Workbooks("DIstributor.xls").Activate
End With
Next MY_SHEETS
End Sub

Thanks in advance.

Bob Phillips
10-12-2008, 02:47 AM
I think this might be close to what you mean



Sub COPY_TO_DISTRIBUTOR()
Dim wbSource As Workbook
Dim wbTarget As Workbook
Dim wsTarget As Worksheet
Dim LastRow As Long
Dim i As Long

Set wbSource = Workbooks("DISTRIBUTOR.xls")
Set wbTarget = Workbooks("Master.xls")

With wbSource.Worksheets(1)

LastRow = .Cells(.Rows.cout, "A").End(xlUp).Row
For i = 1 To LastRow Step 10

Set wsTarget = wbTarget.Worksheets.Add
.Rows(i).Resize(10).Copy wsTarget.Range("A1")
Next i
End With
End Sub