+ Reply to Thread
Results 1 to 3 of 3

combine cellcontents based on comparison multiple cells

Hybrid View

  1. #1
    Registered User
    Join Date
    08-07-2011
    Location
    Soest
    MS-Off Ver
    Excel 2003
    Posts
    2

    combine cellcontents based on comparison multiple cells

    Hi,

    I am really stuck on this.

    My sheet is as follows:

    A             B           C              D                   E
    name       Address     Postal      Country                Account
    John        Street         151          FR                123
    Pete        Strasse        202          DE                456
    John        Street         151          FR                789
    John        Street         888          FR                111
    I would like to have all doubles removed and their unique accounts into one cell.
    In this example John occurs twice with the same address, postal and country, so his account is combined. The 888 should not be combined as it is not the same John.

    My result would look like:

    A             B           C              D                   E
    name       Address     Postal      Country                Account
    John        Street         151          FR                123, 789
    Pete        Strasse        202          DE                456
    John        Street         888          FR                111
    I hope anyone is able to help me, I have been trying in VBA but no luck so far.
    Last edited by scarm; 08-07-2011 at 03:33 PM.

  2. #2
    Valued Forum Contributor
    Join Date
    02-12-2011
    Location
    The Netherlands
    MS-Off Ver
    365
    Posts
    818

    Re: combine cellcontents based on comparison multiple cells

    Something like this scarm?
    Sub HSV()
    Dim n As Integer, old As Variant, tel1 As Integer, i As Integer, place As Variant, k As Integer, code As Variant
        Range("G2:K" & Cells(Rows.Count, 7).End(xlUp).Row).ClearContents
          Range("A3:E" & Cells(Rows.Count, 1).End(xlUp).Row).Sort Key1:=[A3], Key2:=[B3], key3:=[C3]
          Range("F1") = Range("A3:A" & Cells(Rows.Count, 1).End(xlUp).Row).Rows.Count
         n = Range("F1").Value
         Range("G1:K1").Value = Range("A2:E2").Value
        old = "!@#&$"
         tel1 = 0
        For i = 1 To n
          place = Cells(i + 2, 1).Value & "|" & Cells(i + 2, 2).Value & "|" & Cells(i + 2, 3).Value & "|" & Cells(i + 2, 4).Value
             If place <> old Then
               tel1 = tel1 + 1
                Cells(tel1 + 1, 7).Resize(, 4).Value = Split(place, "|")
                  old = place
                 k = 11
               End If
             code = Cells(i + 2, 5).Value
             If Cells(tel1 + 1, k) = "" Then
             Cells(tel1 + 1, k) = code
             Else
          Cells(tel1 + 1, k).Value = Cells(tel1 + 1, k) & " , " & code
          End If
        Next i
    End Sub
    Attached Files Attached Files
    Kind regards, Harry.

  3. #3
    Registered User
    Join Date
    08-07-2011
    Location
    Soest
    MS-Off Ver
    Excel 2003
    Posts
    2

    Re: combine cellcontents based on comparison multiple cells

    Thank you very much this is exactly what I needed!

+ 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