+ Reply to Thread
Results 1 to 3 of 3

Help with looping a macro

Hybrid View

  1. #1
    Registered User
    Join Date
    11-21-2012
    Location
    usa
    MS-Off Ver
    Excel 2007
    Posts
    2

    Help with looping a macro

    Hi,

    New to all of this (as in first day!) and I've managed to cobble a couple of macros together to format a worksheet but I need help with this one in particular.

    What I have so far is what I've recorded myself. I'm trying to copy a selection of cells from a row and transpose them into a (pre-existing) column. What I need to have happen is for this macro to repeat down the page until there are no more rows to transpose.

    Each row has unique data so I am not looking to repeat a single row down the page. Each row I am transposing exists from columns E:Q. Each row will transpose into column D. Also, each row with data that I am transposing has 12 blank rows between it (in order to fit the row turned column).

    So it should select, transpose, delete, skip 12 rows, select, transpose, delete, skip 12 rows, etc. Here is the code I have so far and a before and after screen shot. Thanks for any help.

    Sub transpose_qty()
    ' transpose_qty Macro
    Range("E2:Q2").Select
    Selection.Copy
    Range("D2").Select
    Selection.PasteSpecial Paste:=xlPasteAll, Operation:=xlNone, SkipBlanks:= _
    False, Transpose:=True
    Range("E2:Q2").Select
    Application.CutCopyMode = False
    Selection.ClearContents
    End Sub
    Attached Images Attached Images

  2. #2
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 365 on Win11 (desktop), 2019 on Win11 (notebook)
    Posts
    8,198

    Re: Help with looping a macro

    Hi, jumpingoff,

    maybe start opff with somehting like this:
    Sub Transpose_re()
    Dim lngLastRow As Long
    Dim lngCounter As Long
    
    Const clngNO_Col As Long = 13
    
    lngLastRow = Cells(Rows.Count, "E").End(xlUp).Row
    For lngCounter = 2 To lngLastRow Step clngNO_Col
      Range("D" & Cells(Rows.Count, "D").End(xlUp).Row + 1).Resize(clngNO_Col, 1).Value = _
          WorksheetFunction.transpose(Cells(lngCounter, "E").Resize(1, clngNO_Col))
    Next lngCounter
    End Sub
    Ciao,
    Holger
    Use Code-Tags for showing your code: [code] Your Code here [/code]
    Please mark your question Solved if there has been offered a solution that works fine for you

  3. #3
    Registered User
    Join Date
    11-21-2012
    Location
    usa
    MS-Off Ver
    Excel 2007
    Posts
    2

    Re: Help with looping a macro

    Thanks Holger! Worked perfectly.

+ 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