Consulting

Results 1 to 4 of 4

Thread: Copy rows and paste them to new sheet

  1. #1
    VBAX Regular
    Joined
    Oct 2014
    Posts
    24
    Location

    Red face Copy rows and paste them to new sheet

    Hello!

    I'm looking for a macro that will copy rows 1&2 of Sheet1, then paste (transpose) those rows on to a new sheet (Sheet2). Then, copy rows 1&3 and transpose to a new sheet (Sheet3). Then, copy rows 1&4 and transpose to a new sheet (Sheet4), and so on... Is this possible? I have 200 rows in total, and would hate to do this manually.

    Candidate Q1 Q2 Q3 Q4 Q5
    Jim y z 1 2 3
    Bill x x x x x
    Steve u u u u u
    Teeg 1 2 2 2 1
    Jip 4 g g g g

    Thanks!!

  2. #2
    VBAX Guru mancubus's Avatar
    Joined
    Dec 2010
    Location
    "Where I lay my head is home" :D
    Posts
    2,644
    try:
    Sub vbax_55295_copy_header_and_rows_accross_new_sheets()
    
        Dim tblArr
        Dim i As Long
        
        tblArr = Worksheets("Sheet1").Cells(1).CurrentRegion.Value 'Change Sheet1 to suit
        
        For i = 2 To UBound(tblArr)
            With Worksheets.Add(After:=Worksheets(Worksheets.Count))
                .Range("A1").Resize(UBound(tblArr, 2)).Value = Application.Transpose(Application.Index(tblArr, 1, 0))
                .Range("B1").Resize(UBound(tblArr, 2)).Value = Application.Transpose(Application.Index(tblArr, i, 0))
            End With
        Next i
    
    End Sub
    http://snb-vba.eu/VBA_Arrays_en.html
    Last edited by mancubus; 02-29-2016 at 04:01 PM. Reason: comment added for sheet name
    PLS DO NOT PM; OPEN A THREAD INSTEAD!!!

    1) Posting Code
    [CODE]PasteYourCodeHere[/CODE]
    (or paste your code, select it, click # button)

    2) Uploading File(s)
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) (multiple files can be selected while holding Ctrl key) / Upload Files / Done
    Replace company specific / sensitive / confidential data. Include so many rows and sheets etc in the uploaded workbook to enable the helpers visualize the data and table structure. Helpers do not need the entire workbook.

    3) Testing the Codes
    always back up your files before testing the codes.

    4) Marking the Thread as Solved
    from Thread Tools (on the top right corner, above the first message)

  3. #3
    VBAX Regular
    Joined
    Oct 2014
    Posts
    24
    Location
    @mancubus This is perfect! Exactly what I was looking for. Thank you very much.

  4. #4
    VBAX Guru mancubus's Avatar
    Joined
    Dec 2010
    Location
    "Where I lay my head is home" :D
    Posts
    2,644
    you are welcome.

    thanks for the feedback and marking the thread as solved.

    i added a comment for sheet that houses the table.
    PLS DO NOT PM; OPEN A THREAD INSTEAD!!!

    1) Posting Code
    [CODE]PasteYourCodeHere[/CODE]
    (or paste your code, select it, click # button)

    2) Uploading File(s)
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) (multiple files can be selected while holding Ctrl key) / Upload Files / Done
    Replace company specific / sensitive / confidential data. Include so many rows and sheets etc in the uploaded workbook to enable the helpers visualize the data and table structure. Helpers do not need the entire workbook.

    3) Testing the Codes
    always back up your files before testing the codes.

    4) Marking the Thread as Solved
    from Thread Tools (on the top right corner, above the first message)

Posting Permissions

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