Skip to content

Instantly share code, notes, and snippets.

@jlock6000
Created April 24, 2014 08:33
Show Gist options
  • Save jlock6000/11246605 to your computer and use it in GitHub Desktop.
Save jlock6000/11246605 to your computer and use it in GitHub Desktop.
Excel - Remove duplicates from two lists
Sub DelDups_TwoLists()
Dim iListCount As Integer
Dim iCtr As Integer
' Ark1 must contain the items which must be removed from Ark2
' Turn off screen updating to speed up macro.
Application.ScreenUpdating = False
' Get count of records to search through (list that will be deleted).
iListCount = Sheets("ark2").Cells(Rows.Count, "A").End(xlUp).Row
' Loop through the "master" list.
For Each x In Sheets("Ark1").Range("A1:A" & Sheets("Ark1").Cells(Rows.Count, "A").End(xlUp).Row)
' Loop through all records in the second list.
For iCtr = iListCount To 1 Step -1
' Do comparison of next record.
' To specify a different column, change 1 to the column number.
If x.Value = Sheets("Ark2").Cells(iCtr, 1).Value Then
' If match is true then delete row.
Sheets("Ark2").Cells(iCtr, 1).EntireRow.Delete
End If
Next iCtr
Next
Application.ScreenUpdating = True
MsgBox "Done!"
End Sub
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment