+ Reply to Thread
Results 1 to 7 of 7

comparing lists

Hybrid View

  1. #1
    Registered User
    Join Date
    05-24-2007
    Posts
    73

    comparing lists

    I have two Excel lists. One master list (list A) contains all our email addresses from our customers. The other list (list B) contains a list of people who do NOT want to recieve emails. How do I take the emails from list B (there are 1,200 of them) and compare them automatically to list A? Basically if any email address from list B appears in list A, I want it to delete in list A.

    is that possible?

    thank you

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

    Re: comparing lists

    Hello jspinx,

    Are these lists on the same worksheet? If so, do the lists share any rows?
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

  3. #3
    Registered User
    Join Date
    05-24-2007
    Posts
    73

    Re: comparing lists

    Hello Leith
    they are on different files. Each entry is a different row

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

    Re: comparing lists

    Hello jspinx,

    Good, that makes life much easier. I'll start coding the macro.

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

    Re: comparing lists

    Hello jspinx,

    This will remove the emails on the Master list that appear on the Do Not Email list. You can change the list location and starting cells (marked in red) to match what you are using.
    Sub CleanEmailList()
    
      Dim Cell As Range
      Dim DoNotEmail As Object
      Dim Key As String
      Dim Master As Range
      Dim NoList As Range
      Dim R As Long
      Dim Rng As Range
      Dim RngEnd As Range
      
       'Define the location and start of each list
        Set Master = Worksheets("Sheet1").Range("A2")
        Set NoList = Worksheets("Sheet2").Range("A2")
        
        Set DoNotEmail = CreateObject("Scripting.Dictionary")
        DoNotEmail.CompareMode = vbTextCompare
        
          'Find the range length of the list of addresses not to email
           Set Rng = NoList
           Set RngEnd = Rng.Parent.Cells(Rows.Count, Rng.Column).End(xlUp)
           Set Rng = IIf(RngEnd.Row < Rng.Row, Rng, Rng.Parent.Range(Rng, RngEnd))
           
          'Load the list of addresses not to email
           For Each Cell In Rng
             Key = Trim(Cell.Text)
             If Key <> "" And DoNotEmail.Exists(Key) = False Then
                DoNotEmail.Add Key, 1
             End If
           Next Cell
           
          'Find the range legnth of Master List
           Set Rng = Master
           Set RngEnd = Rng.Parent.Cells(Rows.Count, Rng.Column).End(xlUp)
           Set Rng = IIf(RngEnd.Row < Rng.Row, Rng, Rng.Parent.Range(Rng, RngEnd))
           
             For R = Rng.Rows.Count To 1 Step -1
               Key = Trim(Rng.Cells(R, 1).Text)
                 If Key <> "" And DoNotEmail.Exists(Key) = True Then
                    Rng.Rows(R).EntireRow.Delete
                 End If
             Next R
             
         'Release object and free memory
          Set DoNotEmail = Nothing
          
    End Sub

  6. #6
    Registered User
    Join Date
    05-24-2007
    Posts
    73

    Re: comparing lists

    wow thanks a lot!

  7. #7
    Registered User
    Join Date
    05-30-2009
    Location
    Mexico
    MS-Off Ver
    Excel 2007
    Posts
    4

    Re: comparing lists

    Try using the compare2lists freeware found at the following address: http://sites.google.com/site/compare2lists/

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

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