Help finding duplicates and deleteing the whole row its in

nplano1

New Member
Joined
Sep 6, 2014
Messages
22
HELP FINDING DUPLICATES AND DELETEING THE WHOLE ROW ITS IN

I have a database that contains somewhere between 7 and 10 thousand records all in column A and every month I download a data set that contains between 70 and 100 thousand Records, this goes from column A through column L.
I want to check column A in my database against column A in the dataset that I downloaded and if there are any duplicates I wanted to delete the whole row in the dataset that I just downloaded not the database and at the end of it I would like to know how many duplicates were removed.

This is what I tryed

Sub RemovePhoneNumbers()
Dim WSL As Worksheet
Dim WSD As Worksheet
Dim WBT As Workbook
Dim WBD As Workbook
Dim iRange As Range
Set WBT = ThisWorkbook
Set WBD = ActiveWorkbook
If WBT.Name = WBD.Name Then
MsgBox "Switch to the data worksheet first. Then run the macro."
Exit Sub
End If

Set WSD = ActiveSheet

Set up the criteria range
Set WSL = Worksheets("NUMBERS TO TAKE OUT")
FinalRow = WSL.Cells(Rows.Count, 1).End(xlUp).Row
WSL.Cells(1, 1).Resize(FinalRow, 1).Name = "OutList"

Set up the input range
FinalRow = WSD.Cells(Rows.Count, 1).End(xlUp).Row
FinalCol = WSD.Cells(1, Columns.Count).End(xlToLeft).Column
Set iRange = WSD.Cells(1, 1).Resize(FinalRow, FinalCol)

Make sure the criteria range is correct
For i = 1 To 1
HdFound = False
ThisHeading = WSL.Cells(1, i).Value
For j = 1 To FinalCol
If WSD.Cells(1, j).Value = ThisHeading Then
HdFound = True
Exit For
End If
Next j
If Not HdFound Then
Msg = "Nick - the Numbers to Remove worksheet has a heading in column " & i & " of " & ThisHeading & ". This needs to match a heading in row 1 of " & WSD.Name & "."
MsgBox Msg
Exit Sub
End If
Next i

Find the items to Remove
iRange.AdvancedFilter Action:=xlFilterInPlace, CriteriaRange:= _
Range("OutList"), Unique:=False

FoundCount = iRange.Columns(1).SpecialCells(xlCellTypeVisible).Count - 1
If FoundCount = 0 Then
WSD.ShowAllData
MsgBox "Nothing found to delete."
Exit Sub
End If


WSD.Cells(2, 1).Resize(FinalRow - 1, 1).SpecialCells(xlCellTypeVisible).EntireRow.Delete
WSD.ShowAllData
WSD.Cells(1, 1).Select
MsgBox "Removed " & FoundCount & " rows."
End Sub
 

Excel Facts

How to change case of text in Excel?
Use =UPPER() for upper case, =LOWER() for lower case, and =PROPER() for proper case. PROPER won't capitalize second c in Mccartney
Hello,

does this work as expected?

Have assumed your sheets are called Database and Download and than column M is available in the Download sheet

Code:
Sub REMOVE_DUPLICATES()
    Application.ScreenUpdating = False
    MY_LAST_ROW = Range("A" & Rows.Count).End(xlUp).Row
    Sheets("Download").Select
    Range("M2").Formula = "=MATCH(A2,Database!A:A,0)"
    Range("M2").Copy
    Range("M3:M" & Range("A" & Rows.Count).End(xlUp).Row).PasteSpecial (xlPasteAll)
    Range("M1").Select
    Selection.AutoFilter
    Selection.AutoFilter Field:=13, Criteria1:=">0"
    Range("A2:M" & Rows.Count).SpecialCells(xlCellTypeVisible).Select
    Range("A2:M" & Rows.Count).SpecialCells(xlCellTypeVisible).Delete (xlUp)
    Selection.AutoFilter
    Columns("M:M").ClearContents
    MY_NEW_LAST_ROW = Range("A" & Rows.Count).End(xlUp).Row
    MsgBox MY_LAST_ROW - MY_NEW_LAST_ROW & " rows removed", vbOKOnly, " REMOVED"
    Application.ScreenUpdating = True
End Sub
 
Last edited:
Upvote 0
Solution

Forum statistics

Threads
1,203,454
Messages
6,055,539
Members
444,794
Latest member
HSAL

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