+ Reply to Thread
Results 1 to 3 of 3

Merge Cells depending on another column

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

    Question Merge Cells depending on another column

    Hi All

    Need some urgent help

    i have worksheet with the following format

    1111 abc
    1111 xyz
    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 merge column b as shown below.
    So i need the above data to appear as

    1111 abc,xyz
    1234 qwe

    thanks
    sp123

  2. #2
    Dave Peterson
    Guest

    Re: Merge Cells depending on another column

    Try this against a copy of your worksheet--it destroys the original data when it
    builds the output:

    Option Explicit
    Sub testme()
    Dim iRow As Long
    Dim LastRow As Long
    Dim FirstRow As Long
    Dim wks As Worksheet

    Set wks = Worksheets("Sheet1")

    With wks
    FirstRow = 1
    LastRow = .Cells(.Rows.Count, "A").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

    And make sure your data is sorted by column A.

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

    sp123 wrote:
    >
    > Hi All
    >
    > Need some urgent help
    >
    > i have worksheet with the following format
    >
    > 1111 abc
    > 1111 xyz
    > 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 merge column b as
    > shown below.
    > So i need the above data to appear as
    >
    > 1111 abc,xyz
    > 1234 qwe
    >
    > thanks
    > sp123
    >
    > --
    > sp123
    > ------------------------------------------------------------------------
    > sp123's Profile: http://www.excelforum.com/member.php...o&userid=31163
    > View this thread: http://www.excelforum.com/showthread...hreadid=521943


    --

    Dave Peterson

  3. #3
    Registered User
    Join Date
    02-03-2006
    Posts
    12
    Can Pls modify the function so that the result would appear on separate cells instead of being separated by commas

    Something like this

    1111 abc xyz
    1234 qwe

+ 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