Hello everyone,
I am new to macros in excel. I found a macro that microsoft posted about comparing two lists or sheets and deletes off of sheet 2, the ones that are on both sheets. It's hard to explain. For example, I have a large customer database of 4,000 + names on my sheet2. I want what is on my sheet 1 (which is my do not call list) to be taken off of sheet2 (the large list). The macro works, but the way it is set up makes me specify the range and column manually in the code. I am trying to modify the macro so i can select in the spreadsheet what i want it to sort through on both sheets. This way i can select the column i want to use in both sheets instead of manually changing it in the file. Below is the macro code. Does anyone have any ideas? Thank you.
--------------------------------------------------------------------------
Sub DelDups_TwoLists()
Dim iListCount As Integer
Dim iCtr As Integer
Application.ScreenUpdating = False
' Get count of records to search through (list that will be deleted).
iListCount = Sheets("sheet2").Range("A1:A100").Rows.Count
' Loop through the "master" list.
For Each x In Sheets("Sheet1").Range("A1:A100")
' Loop through all records in the second list.
For iCtr = 1 To iListCount
' Do comparison of next record.
' To specify a different column, change 1 to the column number.
If x.Value = Sheets("Sheet2").Cells(iCtr, 1).Value Then
' If match is true then delete row.
Sheets("Sheet2").Cells(iCtr, 1).EntireRow.Delete
' Increment counter to account for deleted row.
iCtr = iCtr + 1
End If
Next iCtr
Next
Application.ScreenUpdating = True
MsgBox "Done!"
End Sub
Bookmarks