Merging Column items to row

nischal4487

New Member
Joined
Nov 21, 2007
Messages
45
Hi,
I have entries in columns A - x . I want to have all these entries in one cell with a comma(,) after each of the entry in the column cells.
Ex:-
A
B
C
D

Output required in one cell = A,B,C,D

Please help.

Regards,
Nik
 

Excel Facts

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number
Hi nischal4487,

Try this:

Code:
Option Explicit
Sub Macro1()

    Dim lngLastRow As Long
    Dim lngMyRow As Long
    Dim lngMyCol As Long
    Dim strMyText As String
    
    Application.ScreenUpdating = False

    lngLastRow = Range("A:X").Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
    
    For lngMyRow = 2 To lngLastRow 'Starts at Row 2. Change to suit.
        strMyText = ""
        For lngMyCol = 1 To 24
            If Len(Cells(lngMyRow, lngMyCol)) > 0 Then
                If Len(strMyText) = 0 Then
                    strMyText = Cells(lngMyRow, lngMyCol)
                Else
                    strMyText = strMyText & "," & Cells(lngMyRow, lngMyCol)
                End If
            End If
        Next lngMyCol
        Cells(lngMyRow, 25).Value = strMyText 'Output to Col. Y. Change to suit.
    Next lngMyRow
    
    Application.ScreenUpdating = True

End Sub

Note, only cells that have data in them will form part of the concatenated string. If you don't want this comment out or delete the If Len(Cells(lngMyRow, lngMyCol)) > 0 Then line and its associated End If line.

Regards,

Robert
 
Upvote 0

Forum statistics

Threads
1,214,968
Messages
6,122,509
Members
449,089
Latest member
RandomExceller01

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top