Consulting

Results 1 to 5 of 5

Thread: Excel VBA to Transpose lists

  1. #1
    VBAX Mentor
    Joined
    Jan 2008
    Posts
    384
    Location

    Excel VBA to Transpose lists

    I have a set of categories in column A, and each one has a list attached to it.
    What is the best way using VBA to transpose each of those categories so that each one has its own column with the associated code number, leaving two (2) BLANK spaces between each category.

    See attached worksheet Sheet1

    Using Office 2007
    Attached Files Attached Files

  2. #2
    VBAX Guru Kenneth Hobs's Avatar
    Joined
    Nov 2005
    Location
    Tecumseh, OK
    Posts
    4,956
    Location
    Sub TranposeAB()  
      Dim r As Range, c As Range, sc As Range
      
      Set r = Intersect(Range("A2", Cells(Rows.Count, "B").End(xlUp)), _
        ActiveSheet.UsedRange)
      Set sc = Range("G1")
      
      For Each c In r.Rows
        If c.Cells(1).Value = "" And c.Cells(2).Value = "" Then
          If c.Cells(2).Offset(1).Value <> "" Then Set sc = Cells(1, sc.Column + 4)
          GoTo NextC
        End If
        c.Copy sc.Resize(, 2)
        Set sc = sc.Offset(1)
    NextC:
      Next c
    End Sub

  3. #3
    VBAX Mentor
    Joined
    Jan 2008
    Posts
    384
    Location
    Thanks Kenneth:
    Your code works perfectly. Can you please clarify this bit for me.
    NextC:
    Next c
    Trying to determine if c is = C and its use in the code logic.

  4. #4
    Administrator
    VP-Knowledge Base
    VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    NextC: is a label used by GoTo NextC to skip the intervening lines of code
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  5. #5
    VBAX Mentor
    Joined
    Jan 2008
    Posts
    384
    Location
    Thanks mdmackillo :

    I was wondering about that. Using NextC: is a label really threw me for a curve.

Posting Permissions

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