+ Reply to Thread
Results 1 to 4 of 4

Concatenating rows into a single cell

Hybrid View

  1. #1
    Registered User
    Join Date
    09-20-2013
    Location
    Malaysia
    MS-Off Ver
    Excel 2019
    Posts
    57

    Concatenating rows into a single cell

    Is there a way to dynamically concatenate rows into a single cell using VBA code?

    I have a sample where the column highlighted in yellow would be the desired outcome.
    Attached Files Attached Files

  2. #2
    Forum Moderator davesexcel's Avatar
    Join Date
    02-19-2006
    Location
    Regina
    MS-Off Ver
    MS 365
    Posts
    13,523

    Re: Concatenating rows into a single cell

    You can loop through the range areas.

    Sub Button1_Click()
        Dim sh As Worksheet, LastRw As Long
        Dim RangeArea As Range, rng As Range, c As Range
        Dim s As String, x As String
        Set sh = ActiveSheet
     
        With sh
     
            LastRw = .Cells(.Rows.Count, "B").End(xlUp).Row
     
            Set rng = .Range("B2:B" & LastRw)
     
            For Each RangeArea In rng.SpecialCells(xlCellTypeConstants, 23).Areas
                For Each c In RangeArea
                    s = s & c
                Next c
     
                RangeArea(1).Offset(, 1) = s
                s = ""
            Next RangeArea
     
        End With
    End Sub

  3. #3
    Forum Guru
    Join Date
    02-27-2016
    Location
    Vietnam
    MS-Off Ver
    2024
    Posts
    6,175

    Re: Concatenating rows into a single cell

    Or try:

    PHP Code: 
    Public Sub MyConcat()
    Dim lastRow As Long
    Dim i 
    As Long
    Dim temp 
    As String
    lastRow 
    Range("B" Rows.Count).End(xlUp).Row
    For lastRow To 2 Step -1
        temp 
    Range("B" i).Value temp
        
    If Range("A" i).Value <> "" Then
            Range
    ("C" i).Value temp
            temp 
    ""
        
    End If
    Next i
    End Sub 

  4. #4
    Valued Forum Contributor
    Join Date
    06-27-2010
    Location
    sYRIA
    MS-Off Ver
    Excel 2013
    Posts
    669

    Re: Concatenating rows into a single cell

    Hi,
    What about
    Sub Deniouz()
        Dim lr, ar
        lr = Cells(Rows.Count, "B").End(xlUp).Row
        For Each ar In Cells(2, 2).Resize(lr).SpecialCells(xlCellTypeConstants, 23).Areas
            ar.Offset(, 1).Resize(1) = Join(Application.Transpose(ar), "")
        Next
    End Sub
    Last edited by mohadin; 12-20-2020 at 08:39 AM.

+ 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. Replies: 3
    Last Post: 06-18-2016, 08:50 PM
  2. [SOLVED] VBA - combine matching rows and concatenating corresponding rows into one column
    By mjcanty in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 07-02-2015, 12:47 PM
  3. Help Required - Concatenating cells contents into single cell, based on an ID
    By mharis in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-31-2013, 07:49 AM
  4. Replies: 4
    Last Post: 06-06-2012, 02:15 PM
  5. Replies: 1
    Last Post: 02-17-2012, 03:33 AM
  6. Concatenating multiple cells to a single cell between 2 tabs
    By Legacial in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 06-08-2011, 10:12 AM
  7. Macro to split a single cell data into rows and copying other cells as it is in rows
    By Pankaj Sonawane in forum Excel Programming / VBA / Macros
    Replies: 13
    Last Post: 08-25-2010, 07:09 PM

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