Merge rows depending on the value of the first column

  • Thread starter Thread starter sp123
  • Start date Start date
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
 
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
 
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
 
Back
Top