Delete duplicate entry from Column A if it exists in Column B

daniejm

New Member
Joined
Sep 26, 2013
Messages
11
Hi all,

Strangely, Google didn't pop anything up on this. Here's the problem:

I've got a master e-mail list that consists of nearly 64,000 records in Column A and an "unsubscribe" list of about 3,000 records in Column B. The task: to purge our unsubscribe requests (column B) from our master e-mail list (column A).

The two columns need to cross-referenced somehow. If a cell in Column B ("unsubscribe") matches a cell in Column A, the cell in Column A should be deleted. The cross-referencing should not be case sensitive.

What we've tried:
Putting everything into one list and using Remove Duplicates still leaves the original record in Column A, which defeats the purpose. Also, we can't use Conditional Formatting and then a Custom color Filter because the amount of data causes Excel to lock up.

Is there a better way?

Thanks in advance,

Joe
 
Last edited:

Excel Facts

Excel Wisdom
Using a mouse in Excel is the work equivalent of wearing a lanyard when you first get to college
Have you tried using vlookup?


Excel 2010
ABC
1EMAIL 1-LISTEMAIl - LIST 2Helper
2jackson@yahoo.comJohnson@yahoo.comTo be retained
3Johnson@yahoo.comJane@hotmail.comJohnson@yahoo.com
4jane@hotmail.comJane@hotmail.com
5jasmine@gmail.comTo be retained
6jacobson@ulive.comTo be retained
Sheet6
Cell Formulas
RangeFormula
C2=IFERROR(VLOOKUP(A2,$B$2:$B$3,1,0),"To be retained")


Any row that doesn't have "To be retained" can be filtered off and deleted
 
Last edited:
Upvote 0
Here's a VBA solution that should work:

Code:
Sub delete_dups()
  Dim rowLoop As Long, foundRow As Long, test As String
  
  For rowLoop = 1 To Cells(Rows.Count, "B").End(xlUp).Row
    test = Cells(rowLoop, "B")
    
    foundRow = 0
    
    On Error Resume Next
    foundRow = Columns("A").Find(test).Row
    On Error GoTo 0
    
    If Not foundRow = 0 Then
      Cells(foundRow, "A").Delete xlShiftUp
    End If
  Next rowLoop
End Sub


Tim
 
Upvote 0
Have you tried using vlookup?

Excel 2010
ABC
EMAIL 1-LISTEMAIl - LIST 2Helper
jackson@yahoo.comJohnson@yahoo.comTo be retained
Johnson@yahoo.comJane@hotmail.comJohnson@yahoo.com
jane@hotmail.comJane@hotmail.com
jasmine@gmail.comTo be retained
jacobson@ulive.comTo be retained

<colgroup><col style="width: 25pxpx"><col><col><col></colgroup><thead>
</thead><tbody>
[TD="align: center"]1[/TD]

[TD="align: center"]2[/TD]

[TD="align: center"]3[/TD]

[TD="align: center"]4[/TD]

[TD="align: right"][/TD]

[TD="align: center"]5[/TD]

[TD="align: right"][/TD]

[TD="align: center"]6[/TD]

[TD="align: right"][/TD]

</tbody>
Sheet6

[TABLE="width: 85%"]
<tbody>[TR]
[TD]Worksheet Formulas[TABLE="width: 100%"]
<thead>[TR="bgcolor: #DAE7F5"]
[TH="width: 10px"]Cell[/TH]
[TH="align: left"]Formula[/TH]
[/TR]
</thead><tbody>[TR]
[TH="width: 10px, bgcolor: #DAE7F5"]C2[/TH]
[TD="align: left"]=IFERROR(VLOOKUP(A2,$B$2:$B$3,1,0),"To be retained")[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[/TR]
</tbody>[/TABLE]



Any row that doesn't have "To be retained" can be filtered off and deleted

Thanks for the suggestion, MomentMan, but the sheer volume of data and the sheer crappiness of my computer makes the program hard-lock.
 
Upvote 0
Can someone give a brief explanation of how the code below is seeking duplicates in column A (foundRow = 0)? I am using the code for a similar task as OP. While it does work, I have come across a situation where a number is being deleted from the second column when there is no duplicate in the first column? I am wondering if other aspects are coming into play here that I am not considering. :confused:


Here's a VBA solution that should work:

Code:
Sub delete_dups()
  Dim rowLoop As Long, foundRow As Long, test As String
  
  For rowLoop = 1 To Cells(Rows.Count, "B").End(xlUp).Row
    test = Cells(rowLoop, "B")
    
    foundRow = 0
    
    On Error Resume Next
    foundRow = Columns("A").Find(test).Row
    On Error GoTo 0
    
    If Not foundRow = 0 Then
      Cells(foundRow, "A").Delete xlShiftUp
    End If
  Next rowLoop
End Sub


Tim
 
Upvote 0
Can someone give a brief explanation of how the code below is seeking duplicates in column A (foundRow = 0)? I am using the code for a similar task as OP. While it does work, I have come across a situation where a number is being deleted from the second column when there is no duplicate in the first column? I am wondering if other aspects are coming into play here that I am not considering. :confused:
You might try changing the line:

For rowLoop = 1 To Cells(Rows.Count, "B").End(xlUp).Row

to

For rowLoop = Cells(Rows.Count, "B").End(xlUp).Row to 1 Step -1

to avoid a problem that often happens when looping downwards and deleting upwards.


Alternatively, if lots of data, use a faster code such as:
Code:
Sub delete_dups_revisited()

Dim b As Boolean, d As Object, c
Set d = CreateObject("scripting.dictionary")
d.comparemode = 1

For Each c In Range("B1", Range("B" & Rows.Count).End(xlUp)).Value
    d(c) = 1
Next c

For Each c In Range("A1", Range("A" & Rows.Count).End(xlUp))
    If d(c.Value) = 1 Then x = x & "," & c.Address(0, 0): b = True
Next c

If b Then Range(Mid(x, 2)).Delete xlUp Else MsgBox "No matching values"

End Sub
This code may give an (easily fixed) error if there's lots, say 100 or more, values to delete.
 
Upvote 0

Forum statistics

Threads
1,223,908
Messages
6,175,306
Members
452,633
Latest member
DougMo

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top