+ Reply to Thread
Results 1 to 3 of 3

Merge rows depending on the value of the first column

  1. #1
    Registered User
    Join Date
    02-03-2006
    Posts
    12

    Unhappy Merge rows depending on the value of the first column

    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

  2. #2
    Registered User
    Join Date
    05-03-2004
    Posts
    39
    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 Sub

  3. #3
    Registered User
    Join Date
    05-03-2004
    Posts
    39
    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 Sub

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

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