Consulting

Results 1 to 2 of 2

Thread: Macro to Copy only 10 rows per worksheet

  1. #1
    VBAX Newbie
    Joined
    Oct 2008
    Posts
    1
    Location

    Post Macro to Copy only 10 rows per worksheet

    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).

    [vba]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[/vba]

    Thanks in advance.

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    I think this might be close to what you mean

    [vba]

    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
    [/vba]
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •