ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Concatenate rows (https://www.excelbanter.com/excel-programming/370594-concatenate-rows.html)

DD[_2_]

Concatenate rows
 
I need to concatenate rows of a large excel file. This type of data I
recieve every week and need help finding a macro that would fix my
files. I am a baby when it comes programming ;)

What I have:
Name Description
a r
a s
b t
b u
c v
c w

What I need:
Name Description
a r, s
b t, u
c v, w

I would really appreciate any help,
DD


Dave Peterson

Concatenate rows
 
If your data is already sorted by column A:

Option Explicit
Sub testme()

Dim LastRow As Long
Dim FirstRow As Long
Dim iRow As Long
Dim wks As Worksheet

Set wks = Worksheets("sheet1")

With wks
FirstRow = 2 'headers in row 1??
LastRow = .Cells(.Rows.Count, "B").End(xlUp).Row

For iRow = LastRow To FirstRow + 1 Step -1
If .Cells(iRow, "A").Value = .Cells(iRow - 1, "A").Value Then
.Cells(iRow - 1, "B").Value _
= .Cells(iRow - 1, "B").Value & ", " & .Cells(iRow, "B").Value
.Rows(iRow).Delete
End If
Next iRow
End With

End Sub

If you're new to macros, you may want to read David McRitchie's intro at:
http://www.mvps.org/dmcritchie/excel/getstarted.htm

DD wrote:

I need to concatenate rows of a large excel file. This type of data I
recieve every week and need help finding a macro that would fix my
files. I am a baby when it comes programming ;)

What I have:
Name Description
a r
a s
b t
b u
c v
c w

What I need:
Name Description
a r, s
b t, u
c v, w

I would really appreciate any help,
DD


--

Dave Peterson

DD[_2_]

Concatenate rows
 
Thank you! I'll give this a try...
DD



All times are GMT +1. The time now is 02:44 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com