delete code

dennisli

Well-known Member
Joined
Feb 20, 2004
Messages
1,070
Good morning, everyone
I have two ranges containing ID, Sheet1!A1:A1000 and Sheet2!A1:A20.
If any ID in Sheet2!A1:A20 is found in Sheet1!A1:A1000, then the row containing that ID in Sheet2 would be deleted.
Thanks lot.
Dennis
 

Excel Facts

Why does 9 mean SUM in SUBTOTAL?
It is because Sum is the 9th alphabetically in Average, Count, CountA, Max, Min, Product, StDev.S, StDev.P, Sum, VAR.S, VAR.P.
Try

Code:
Sub DelA()
Dim i As Long
With Sheets("Sheet2")
    For i = 20 To i Step -1
        If IsNumeric(Application.Match(.Range("A" & i).Value, Sheets("Sheet1").Columns("A"), 0)) Then .Rows(i).Delete
    Next i
End With
End Sub
 
Upvote 0
Code:
Sub Del_Rows()
Dim Rng As Range
Dim i As Long
Application.ScreenUpdating = False
Set Rng = Sheets("Sheet1").Range("A1:A1000")
With Sheets("Sheet2")
    For i = 20 To 1 Step -1
        If WorksheetFunction.CountIf(Rng, .Cells(i, 1)) > 0 Then .Cells(i, 1).EntireRow.Delete
    Next i
End With
Application.ScreenUpdating = True
 
Upvote 0

Forum statistics

Threads
1,224,551
Messages
6,179,470
Members
452,915
Latest member
hannnahheileen

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