Consulting

Results 1 to 5 of 5

Thread: Solved: A Duplicate finder and Merge all in one

  1. #1
    VBAX Newbie
    Joined
    Nov 2006
    Posts
    2
    Location

    Solved: A Duplicate finder and Merge all in one

    Hey all,
    Was after some assistance in either writing or finding a macro that can help me achieve the following

    Need to find multiple listings of same addresses and merge names of people who live there and delete duplicate

    Needs to first find duplicate rows based upon exact match of Column A and B
    Then once found, Merge the contents of Column C together.
    Then deletes duplicate
    Example
    Row 1
    Col A = 21
    Col B = Foobar Way
    Col C = Mick Jagger

    Row 2
    Col A = 21
    Col B = Foobar Way
    Col C = Bob Marley

    End Result is Row 1 and 2 found to be duplicate, Row 1 Col C has now a value of "Mick Jagger & Bob Marley" and Row 2 is then deleted

    Any assistance would be appriciated

    Hope this all makes sense

    Cheers

  2. #2
    Hi

    This is pretty clumsy but try

    [VBA]
    Type mytype
    street As String
    row As Long
    End Type
    Sub bbb()
    Dim arr() As mytype

    cntr = 1
    ReDim Preserve arr(cntr)
    arr(cntr).street = Range("a1").Value & Range("B1").Value
    arr(cntr).row = 1
    For Each ce In Range("A2:A4")
    For i = 1 To cntr
    If arr(i).street = ce.Value & ce.Offset(0, 1).Value Then
    Cells(arr(i).row, 3).Value = Cells(arr(i).row, 3).Value & " & " & ce.Offset(0, 2).Value
    ce.EntireRow.ClearContents
    i = cntr
    Else
    cntr = cntr + 1
    ReDim Preserve arr(cntr)
    arr(cntr).street = ce.Value & ce.Offset(0, 1).Value
    arr(cntr).row = ce.row
    End If

    Next i
    Next ce
    Range("A1", Cells(Rows.Count, 1).End(xlUp)).SpecialCells(xlCellTypeBlanks).EntireRow.Delete
    End Sub
    [/VBA]



    Tony

  3. #3
    Moderator VBAX Guru Ken Puls's Avatar
    Joined
    Aug 2004
    Location
    Nanaimo, BC, Canada
    Posts
    4,001
    Location
    Hi there,

    For dealing with duplicates, I always like to recommend Dave Brett's Duplicate Master.

    I'm trying to visualize your data though, and I'm not sure if this would work for you or not...
    Ken Puls, CMA - Microsoft MVP (Excel)
    I hate it when my computer does what I tell it to, and not what I want it to.

    Learn how to use our KB tags! -||- Ken's Excel Website -||- Ken's Excel Forums -||- My Blog -||- Excel Training Calendar

    This is a shameless plug for my new book "RibbonX - Customizing the Office 2007 Ribbon". Find out more about it here!

    Help keep VBAX clean! Use the 'Thread Tools' menu to mark your own threads solved!





  4. #4
    VBAX Expert
    Joined
    Feb 2005
    Location
    Nanaimo, British Columbia, Cananda
    Posts
    568
    Location
    Hi Rucas,

    This might work.

    [vba]
    Sub DeleteAndMerge()

    Dim i As Long
    Dim dCol As Long
    Dim lrow As Long

    'Column to check first (A)
    dCol = 1

    'Get last row of data, Col A
    lrow = Cells(65536, dCol).End(xlUp).Row

    'Check each row: lastrow to row 2
    For i = lrow To 2 Step -1

    'If Col A AND Col B are match
    If Cells(i, 1) = Cells(i - 1, 1) And Cells(i, 2) = Cells(i - 1, 2) Then

    'Col C = Concatentate Col C names
    Cells(i - 1, 3) = Cells(i - 1, 3) & " & " & Cells(i, 3)

    'Delete dupe row
    Cells(i, 1).EntireRow.Delete
    End If
    Next i
    End Sub
    [/vba]

    Cheers,

    dr

  5. #5
    VBAX Newbie
    Joined
    Nov 2006
    Posts
    2
    Location
    Quote Originally Posted by rbrhodes
    Hi Rucas,

    This might work.

    [vba]
    Sub DeleteAndMerge()

    Dim i As Long
    Dim dCol As Long
    Dim lrow As Long

    'Column to check first (A)
    dCol = 1

    'Get last row of data, Col A
    lrow = Cells(65536, dCol).End(xlUp).Row

    'Check each row: lastrow to row 2
    For i = lrow To 2 Step -1

    'If Col A AND Col B are match
    If Cells(i, 1) = Cells(i - 1, 1) And Cells(i, 2) = Cells(i - 1, 2) Then

    'Col C = Concatentate Col C names
    Cells(i - 1, 3) = Cells(i - 1, 3) & " & " & Cells(i, 3)

    'Delete dupe row
    Cells(i, 1).EntireRow.Delete
    End If
    Next i
    End Sub
    [/vba]

    Cheers,

    dr
    Worked beautifully.. exactly what I needed
    Couldn't of asked for more..
    Thankyou soo much

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •