+ Reply to Thread
Results 1 to 4 of 4

VBA Macro to Transpose Columns to Rows AND Concatenate Afterwards

Hybrid View

  1. #1
    Registered User
    Join Date
    07-29-2013
    Location
    New York, NY
    MS-Off Ver
    Excel 2010
    Posts
    2

    VBA Macro to Transpose Columns to Rows AND Concatenate Afterwards

    Hello,

    First post: urgent question.

    Data looks like this:

    Joe, Bob
    Madison, Billy
    Drew, Larry

    Ying, Min
    Yong, Mong

    Ting, Tong
    John, Jacob


    Not only do I need to develop a macro to transpose each of these sets (separated by spaces) into columns, but also I need to then combine them into one cell separated by a space.

    The key here: to develop a code to concatenate everything into the first cell, but just run it once so that it will know to group together only the ones separated by spaces all the way down to yield the following

    Joe, Bob , Madison, Billy , Drew, Larry

    Ying, Min , Yong, Mong

    Ting, Tong , John, Jacob

  2. #2
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: VBA Macro to Transpose Columns to Rows AND Concatenate Afterwards

    Hi ljanak,

    Here's a quickie working from ActiveCell - you'll need to have the first cell selected:

    Sub Janak(): Dim S As String, i As Integer
    GetS: S = ActiveCell
    For i = 1 To 100
    If ActiveCell.Offset(i, 0) <> "" Then
    S = S & " , " & ActiveCell.Offset(i, 0)
    Else: ActiveCell.Offset(0, 1) = S: S = ""
    If ActiveCell.Offset(i + 1, 0) <> "" Then
    ActiveCell.Offset(i + 1, 0).Select
    GoTo GetS
    Else: Exit Sub: End If
    End If: Next i
    End Sub
    If I've helped you, please consider adding to my reputation - just click on the liitle star at the left.

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~(Pride has no aftertaste.)

    You can't do one thing. XLAdept

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~aka Orrin

  3. #3
    Registered User
    Join Date
    07-29-2013
    Location
    New York, NY
    MS-Off Ver
    Excel 2010
    Posts
    2

    Re: VBA Macro to Transpose Columns to Rows AND Concatenate Afterwards

    Thank you for your post! I am new to the site- is there a way to acknowledge your help to give you credit, etc.?

    I found that the following worked better for my purposes:



    Sub Beautify()
    Dim R As Range, Idx As Long
    
        Set R = Selection
        Idx = 1
    
        Do While Idx < R.Rows.Count                           ' count dynamically changes as we delete rows
            If R(Idx + 1, 1) = "" Then                        ' found a break line looking 1 down
                R(Idx, 3) = R(Idx, 3) & " , " & R(Idx + 1, 3)   ' append to current
                R(Idx + 1, 1).EntireRow.Delete                ' delete following but do not count up Idx
            Else
                Idx = Idx + 1                                 ' this one is clean, advance
            End If
        Loop
    End Sub

  4. #4
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: VBA Macro to Transpose Columns to Rows AND Concatenate Afterwards

    Hi ljanak,

    You can go to my post and click on the little start to give me rep - but you didn't need my quickie

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Macro to transpose rows to columns
    By escodc in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 06-25-2013, 03:15 PM
  2. [SOLVED] Macro to Transpose variable columns into rows
    By Awalgaonkar in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 03-18-2013, 01:11 PM
  3. [SOLVED] Macro to Transpose data in rows to columns
    By Shanthuday in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-22-2012, 08:00 AM
  4. [SOLVED] Macro to Transpose Columns Into Rows
    By boldcode in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 05-02-2011, 04:44 PM
  5. Macro to transpose a set of rows to columns
    By romanzy in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-17-2010, 06:45 PM

Tags for this Thread

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