+ Reply to Thread
Results 1 to 5 of 5

Sorting and merging 2 duplicate columns

  1. #1
    Registered User
    Join Date
    04-20-2012
    Location
    cape town
    MS-Off Ver
    Excel 2007
    Posts
    9

    Sorting and merging 2 duplicate columns

    Hi
    i have 3 columns as per attached sample file
    id like to be able to
    1: Sort by col A
    2: combine col B to get a total for duplicate in Col A
    3: combine col c to get a total for duplicate in Col A

    so as per attached file the outcome would be

    Col A Col B Col C
    John 111 444
    Paul 222 666


    below is a macro to just sort and combine values in col B bases on col A - this works perfectly - id like to just add on col 3, and also be able to add on more cols as per my need

    Sub SortAndMerge()
    'Sort first
    'NOTE: Change this select if you wish the sort to be more precise
    Cells.Select
    Selection.Sort Key1:=Range("A1"), Order1:=xlAscending, Header:=xlGuess, _
    OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
    DataOption1:=xlSortNormal

    'And then merge
    Range("A1").Select

    'Keep going until we run out of entires in the first column
    Do While ActiveCell.Value <> 0

    'Loop while the row below matches
    Do While ActiveCell.Offset(1, 0).Value = ActiveCell.Value
    'The value on this row += the value on the next row
    'NOTE: Changing the 1 in the second places on *all three* of these
    ' offsets will change the row being merged (A+1=B, A+2=C, etc)
    ActiveCell.Offset(0, 1).Value = ActiveCell.Offset(0, 1).Value _
    + ActiveCell.Offset(1, 1).Value

    'Delete the duplicate row
    ActiveCell.Offset(1, 0).Rows("1:1").EntireRow.Select
    Selection.Delete Shift:=xlUp

    'Reselect the top row for this group
    ActiveCell.Offset(-1, 0).Select
    Loop

    'Step to next row
    ActiveCell.Offset(1, 0).Select
    Loop
    End Sub





    Your help would be really appreciated!!!!!!

    Thanks
    MESH
    Attached Files Attached Files

  2. #2
    Forum Expert nilem's Avatar
    Join Date
    10-22-2011
    Location
    Ufa, Russia
    MS-Off Ver
    2013
    Posts
    3,377

    Re: Sorting and merging 2 duplicate columns

    Hi MESH, try it
    Please Login or Register  to view this content.

  3. #3
    Registered User
    Join Date
    04-20-2012
    Location
    cape town
    MS-Off Ver
    Excel 2007
    Posts
    9

    Re: Sorting and merging 2 duplicate columns

    it combines prefectly! Than ks!!!
    but unfortunately it doesnt sort by col A. it also combines col A so as per example you get PaulPaul and JohnJohn

  4. #4
    Forum Expert nilem's Avatar
    Join Date
    10-22-2011
    Location
    Ufa, Russia
    MS-Off Ver
    2013
    Posts
    3,377

    Re: Sorting and merging 2 duplicate columns

    Oops, that's the correct code
    Please Login or Register  to view this content.
    And please add the tag code in your first post
    Last edited by nilem; 06-28-2012 at 06:27 AM.

  5. #5
    Registered User
    Join Date
    04-20-2012
    Location
    cape town
    MS-Off Ver
    Excel 2007
    Posts
    9

    Re: Sorting and merging 2 duplicate columns

    once again this forum has been absolutely brilliant
    thanks so much

+ 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