Consulting

Results 1 to 7 of 7

Thread: VBA to stack top row into columns

  1. #1

    Question VBA to stack top row into columns

    Hey guys I have a request. If I have the top row with data from "A1 to I1", "K1 to S1" and it goes like that until ZA1 or something like that, so they are groups of 9 cells together, how could I stack them all together from "A1 to I1" and then K1 to S1 would go to A2 to I2 and U1 to AC1 would go to A3 to I3 and so on. Any help would be appreciated.

    Thanks.

  2. #2
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,728
    Location
    something like that
    Option Explicit
    
    Sub Stack()
        Dim i As Long, iLast As Long, iOut As Long
        
        With ActiveSheet
            iLast = .Cells(1, .Columns.Count).End(xlToLeft).Column
            
            iOut = 2
            For i = 11 To iLast Step 10
                .Cells(1, i).Resize(1, 9).Copy .Cells(iOut, 1)
                iOut = iOut + 1
            Next i
        End With
    End Sub
    Attached Files Attached Files
    ---------------------------------------------------------------------------------------------------------------------

    Paul


    Remember: Tell us WHAT you want to do, not HOW you think you want to do it

    1. Use [CODE] ....[/CODE ] Tags for readability
    [CODE]PasteYourCodeHere[/CODE ] -- (or paste your code, select it, click [#] button)
    2. Upload an example
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) / Upload Files / Done
    3. Mark the thread as [Solved] when you have an answer
    Thread Tools (on the top right corner, above the first message)
    4. Read the Forum FAQ, especially the part about cross-posting in other forums
    http://www.vbaexpress.com/forum/faq...._new_faq_item3

  3. #3

    Thanksssss a lotttttt!!!!

    I don't know how it is so easy for you, I mean easy because it was not long ago I posted the request. Thanks a lot, you really saved me a lot of time.

  4. #4
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,728
    Location
    1. No Problem

    2. It's usually the analysis that takes a while, the VBA part is usually easier so look over my macro and see what it's doing so that you can make your own changes if needed. Come back if there are any more questions

    3. You can use [Thread Tools] above your first post to mark this [Solved]
    ---------------------------------------------------------------------------------------------------------------------

    Paul


    Remember: Tell us WHAT you want to do, not HOW you think you want to do it

    1. Use [CODE] ....[/CODE ] Tags for readability
    [CODE]PasteYourCodeHere[/CODE ] -- (or paste your code, select it, click [#] button)
    2. Upload an example
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) / Upload Files / Done
    3. Mark the thread as [Solved] when you have an answer
    Thread Tools (on the top right corner, above the first message)
    4. Read the Forum FAQ, especially the part about cross-posting in other forums
    http://www.vbaexpress.com/forum/faq...._new_faq_item3

  5. #5
    Thanks bud, the thread is marked as solved. Thanks a lot again and for now it doesn't look like I need to make any changes to it. Thanks

  6. #6
    Knowledge Base Approver VBAX Wizard
    Joined
    Apr 2012
    Posts
    5,646
    This code is sufficient (remove Option Explicit)

    Sub M_snb()
        For Each ar In Rows(1).SpecialCells(2).Areas
           Cells(Rows.Count, 1).End(xlUp).Offset(1).Resize(, ar.Columns.Count) = ar.Value
        Next
    End Sub

  7. #7
    Thanks!!!

Posting Permissions

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