+ Reply to Thread
Results 1 to 11 of 11

Compare two email lists and output non-matching

Hybrid View

  1. #1
    Registered User
    Join Date
    11-20-2008
    Location
    AUSTRALIA
    Posts
    4

    Compare two email lists and output non-matching

    Hi,

    I am a newbie and need your expert help please.

    I have two email lists. For example they are:

    List 1:

    a@spam.com
    b@spam.com
    c@spam.com

    List 2:

    abcdef@spam.com
    b@spam.com
    c@spam.com

    In list 1 the non-matching address is a@spam.com. namely it is not common to both lists. I want to automatically go through the lists and output firstly a new list of the non-matches from column 1 and also a new list of the non-common items from list two.

    So in this case the result would be that somewhere there is a new list from list 1 that has "a@spam.com" and secondly there is a new list from list 2 that has "abcdef@spam.com."

    Obvioulsy the real list is more complicated and longer but the principle will be the same.

    Can anyone help please?
    Last edited by NBVC; 11-26-2008 at 08:32 AM.

  2. #2
    Forum Expert NBVC's Avatar
    Join Date
    12-06-2006
    Location
    Mississauga, CANADA
    MS-Off Ver
    2003:2010
    Posts
    34,898
    In a column near List1 use a formula like this:

    =Isnumber(Match(A1,B:B,0)) where A1 is the first address to search for and B:B is the entire column B that List 2 is located in. Then copy the formula down.

    You will get TRUE if matches are found adn FALSE if none are found.

    You can then filter this list through DATA|FILTER|AUTOFILTER, filtering for FALSE and copy/paste it elsewhere.

    You can repeat the process for comparing List2 to List1 , just changing the references in the formula above to suit.
    Where there is a will there are many ways.

    If you are happy with the results, please add to the contributor's reputation by clicking the reputation icon (star icon) below left corner

    Please also mark the thread as Solved once it is solved. Check the FAQ's to see how.

  3. #3
    Registered User
    Join Date
    11-20-2008
    Location
    AUSTRALIA
    Posts
    4
    Hi,

    Thank you for the reply. It is much appreciated. Unfortunately this is not the solution that I need. I need a different example to explain. Unfortunately the lists are not aligned for comparison in that way.

    List 1

    s12345
    iuygl
    fhflsdihew
    couheui
    erouieh
    etoiujrt
    a123
    a124

    List 2

    iuygl
    s12345
    erouieh
    etoiujrt
    couheui
    a124

    If you compared these lists as they are using the solution that you have provided all would read false even though there is significant overlap of content between the lists.

    Now I expect that you will say "sort the lists first". In this case your solution is closer to the mark but would still require a lot of manual iterations to come away with the resulting two lists of exceptions that I desire. In theory some lists would require as much work as sorting them amnually.

    If you have any ideas, given this new information, I would be very grateful for your expert advice. Thank you again for trying to help me.

  4. #4
    Forum Expert NBVC's Avatar
    Join Date
    12-06-2006
    Location
    Mississauga, CANADA
    MS-Off Ver
    2003:2010
    Posts
    34,898
    See attached for example of what I meant...
    Attached Files Attached Files

  5. #5
    Registered User
    Join Date
    11-20-2008
    Location
    AUSTRALIA
    Posts
    4
    Of course! You are the king. Thank you so much.

  6. #6
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259
    Hello Axel_Max,

    Here is another version that is fully automated. Click the button and your done. The macro makes use of the Dictionary object to do the comparisons and remove any duplicates. Here is the macro for those who are interested.
    Sub ListUniques()
    
      Dim I As Long
      Dim Keys1 As Variant
      Dim Keys2 As Variant
      Dim LastRow As Long
      Dim List1 As Object
      Dim List2 As Object
      Dim Rng1 As Range
      Dim Rng2 As Range
      Dim Unique1 As Range
      Dim Unique2 As Range
      
        Set List1 = CreateObject("Scripting.Dictionary")
        Set List2 = CreateObject("Scripting.Dictionary")
        
          List1.CompareMode = 1
          List2.CompareMode = 1
      
          With Worksheets("Sheet1")
           'Define the ranges for List1, List2, Unique1, and Unique2
            LastRow = .Cells(Rows.Count, "A").End(xlUp).Row
              Set Rng1 = IIf(LastRow = 1, .Range("A2"), .Range("A2", .Cells(LastRow, "A")))
            LastRow = .Cells(Rows.Count, "B").End(xlUp).Row
              Set Rng2 = IIf(LastRow = 1, .Range("B2"), .Range("B2", .Cells(LastRow, "B")))
            LastRow = .Cells(Rows.Count, "C").End(xlUp).Row
              Set Unique1 = IIf(LastRow = 1, .Range("C2"), .Range("C2", .Cells(LastRow, "C")))
            LastRow = .Cells(Rows.Count, "D").End(xlUp).Row
              Set Unique2 = IIf(LastRow = 1, .Range("D2"), .Range("D2", .Cells(LastRow, "D")))
          End With
          
           'Create an array of unique values in List1
            For Each Cell In Rng1
              If Not List1.Exists(Cell) Then
                List1.Add Cell.Text, 1
              End If
            Next Cell
            
           'Create an array of unique values in List2
            For Each Cell In Rng2
              If Not List2.Exists(Cell) Then
                List2.Add Cell.Text, 2
              End If
            Next Cell
    
           'Load the comparison arrays
            Keys1 = List1.Keys
            Keys2 = List2.Keys
              
             'Put the unique values of List2 in column "C"
              I = 1
              Unique1.ClearContents
              For Each K In Keys1
                If Not List2.Exists(K) Then
                  Unique1.Item(I) = K
                  I = I + 1
                End If
              Next K
              
             'Put the unique values of List1 in column "D"
              I = 1
              Unique2.ClearContents
              For Each K In Keys2
                If Not List1.Exists(K) Then
                  Unique2.Item(I) = K
                  I = I + 1
                End If
              Next K
    
       'Free memory from objects
        Set List1 = Nothing
        Set List2 = Nothing
              
    End Sub
    Sincerely,
    Leith Ross
    Attached Files Attached Files
    Last edited by Leith Ross; 11-28-2008 at 12:59 AM. Reason: Attached file a second time. First time didn't work.

+ 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