+ Reply to Thread
Results 1 to 8 of 8

Loop, Copy and Transpose

Hybrid View

  1. #1
    Registered User
    Join Date
    11-06-2007
    Posts
    48

    Loop, Copy and Transpose

    Hi, I'm hoping someone can help me out with the following.

    I have data in Col B (+- 9000 rows) and want to copy four cells (starting in "B3:B6") and transpose it in "H2".
    Then find the next 4 cells in col B, copy and transpose this in "H3" and so on

    I need to repeat this till the first empty cell in Col B.

    Unfortunately, i'm struggling with loops and am hoping someone can help.

    Thanks in advance.

  2. #2
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689
    How about just a worksheet function solution?

  3. #3
    Forum Contributor VBA Noob's Avatar
    Join Date
    04-25-2006
    Location
    London, England
    MS-Off Ver
    xl03 & xl 07(Jan 09)
    Posts
    11,988
    Try

    Sub Transposer()
    Dim Lr As Long, i As Long
    Lr = Cells(Rows.Count, "B").End(xlUp).Row
    
    Application.ScreenUpdating = False
        For i = 3 To Lr Step 4
            Range("B" & i, "B" & i + 3).Copy
            Range("H65536").End(xlUp).Offset(1). _
            PasteSpecial Transpose:=True
        Next i
        
    With Application
        .CutCopyMode = False
        .ScreenUpdating = True
    End With
    
    End Sub
    VBA Noob
    _________________________________________


    Credo Elvem ipsum etian vivere
    _________________________________________
    A message for cross posters

    Please remember to wrap code.

    Forum Rules

    Please add to your signature if you found this link helpful. Excel links !!!

  4. #4
    Registered User
    Join Date
    11-06-2007
    Posts
    48
    Thank you very much for your insight.

    What does "Step 4" imply in this instance. Thank you

  5. #5
    Forum Contributor VBA Noob's Avatar
    Join Date
    04-25-2006
    Location
    London, England
    MS-Off Ver
    xl03 & xl 07(Jan 09)
    Posts
    11,988
    i starts from 3 to Lastrow in Col B. The step 4 jumps it to 7.

    So the first i refers to B3 to B6 (i=3 + 3)
    the 2nd refers to B7 to B10 etc

    Range("B" & i, "B" & i + 3).
    HTH

    VBA Noob

  6. #6
    Registered User
    Join Date
    11-06-2007
    Posts
    48
    Thanks again. One last question...

    If i change Offset(1) to Offset(2) then it creates an empty row btw each row that was pasted.

    Range("H65536").End(xlUp).Offset(1).PasteSpecial Transpose:=True
    Is this just a indication of the destination to whihc it is copied, so if i change it to Offset(2) then it should only move to pasted data on row down. Which it does But it also inserts an empty row btw each pasted row.

    Thanks for you time

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1