Consulting

Results 1 to 3 of 3

Thread: Loop to Cut Down on Long Code

  1. #1
    VBAX Mentor
    Joined
    Feb 2016
    Location
    I have lived in many places, I love to Travel
    Posts
    413
    Location

    Loop to Cut Down on Long Code

    Good day folks,


    now my list of transpositons is growing

    i was thinking to use something to make it shorter

    not the most elegant of solutions

    Every 30 rows i transpose

    
       Sub Transpose_Lists()
        
       'Transpose Lists
       
        Dim oWs As Worksheet
        Set oWs = ThisWorkbook.Worksheets("Transpose")
          
          
        '1-30
        oWs.Range("B2:B31").Select
        oWs.Range("D2") = Join(Application.Transpose(Selection))   
        
        '31-60
        
        oWs.Range("B32:B61").Select
        oWs.Range("D4") = Join(Application.Transpose(Selection))   
        
        
         '62 -91
        
        oWs.Range("B62:B91").Select
        oWs.Range("D6") = Join(Application.Transpose(Selection))   
        
        '92 -120
        
        oWs.Range("B92:B120").Select
        oWs.Range("D8") = Join(Application.Transpose(Selection))   
        
        
        oWs.Range("B121:B150").Select
        oWs.Range("D10") = Join(Application.Transpose(Selection))  
    
       ' and growing
        
       
       End Sub

    I once had something similar but i cant work out where to put a loop.

    thank you for any ideas
    Cheers for your help

    dj

    'Extreme VBA Newbie in progress - one step at a time - like a tortoise's pace'


  2. #2
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,726
    Location
    Probably something like this


    Option Explicit
    
    
    Sub Transpose_Lists()
        Dim f As Long, t As Long
        
        With ThisWorkbook.Worksheets("Transpose")
            
            f = 2
            t = 2
            
            Do While Len(.Cells(f, 2).Value) > 0
                .Cells(t, 4).Value = Join(Application.Transpose(.Cells(f, 2).Resize(30, 1)))
                f = f + 30
                t = t + 2
            Loop
            
        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
    VBAX Mentor
    Joined
    Feb 2016
    Location
    I have lived in many places, I love to Travel
    Posts
    413
    Location
    Thanks Paul.

    now that is some awesome fast transposing.

    I can transpose my list so they are manegable in sets.

    then i can paste them into word. and read them properly

    thanks for helping out as always and for the example book

    Thanks again and great day!
    Cheers for your help

    dj

    'Extreme VBA Newbie in progress - one step at a time - like a tortoise's pace'


Posting Permissions

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