+ Reply to Thread
Results 1 to 8 of 8

Loop, Copy and Transpose

Hybrid View

  1. #1
    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 !!!

  2. #2
    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

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

  4. #4
    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

  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
    If column H is empty then the below will return the offset by 1 row of H1 which is H2. If you change it to 2 then it will return H3 e.g two rows etc

    So the larger the offset number the larger gap between rows
    Range("H65536").End(xlUp).Offset(1).
    VBA Noob

  6. #6
    Registered User
    Join Date
    11-06-2007
    Posts
    48
    Thanks again for your willingness to help me understand

+ 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