Merge rows depending on the value of the first column

S

sp123

Hi All,

i have worksheet with the following format

1111 abc
1111 xyz
1111 x12
1234 qwe

I need help to merge column b values depending on column A.If two rows
have the same value in column a then i would like to append the value
of the cells in column b to the first row as shown below.
So i need the above data to appear as

1111 abc xyz x12
1234 qwe

thanks
sp123
 
A

as_sass

sp123,

I had the same problem, and the code below (courtesy of "PY
Associates") worked like a charm for me.

sass


Sub SearchAndAppend()
Range("A1").CurrentRegion.Select
Selection.Sort Key1:=Range("A1")
lrow = Selection.Rows.Count

For i = lrow To 2 Step -1
If Range("A" & i) <> Range("A" & i - 1) Then GoTo donothing
lcol = Range("A" & i, Range("A" & i).End(xlToRight)).Columns.Count
Range(Cells(i, 2), Cells(i, lcol)).Copy
lcol = Range("A" & i - 1, Range("A" & i
1).End(xlToRight)).Columns.Count
Cells(i - 1, lcol + 1).Select
ActiveSheet.Paste
Range("A" & i).EntireRow.Delete
donothing:
Next i

End Su
 
A

as_sass

sp123,

I had the same problem, and the code below (courtesy of "PY
Associates") worked like a charm for me.

sass


Sub SearchAndAppend()
Range("A1").CurrentRegion.Select
Selection.Sort Key1:=Range("A1")
lrow = Selection.Rows.Count

For i = lrow To 2 Step -1
If Range("A" & i) <> Range("A" & i - 1) Then GoTo donothing
lcol = Range("A" & i, Range("A" & i).End(xlToRight)).Columns.Count
Range(Cells(i, 2), Cells(i, lcol)).Copy
lcol = Range("A" & i - 1, Range("A" & i
1).End(xlToRight)).Columns.Count
Cells(i - 1, lcol + 1).Select
ActiveSheet.Paste
Range("A" & i).EntireRow.Delete
donothing:
Next i

End Su
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top