Macro to delete specific rows

G

Gert-Jan

Hi,

In sheet1, range A1:p40 I have values. In the range A1:A40 there are ID
numbers. In sheet2, range (A1:A10) there are also ID numbers, wich might
correspondend to the range A1:A40 in Sheet1. I want a macro that deletes the
rows in sheet1 with the ID-numbers that are in sheet2.

Any help would be appriciated.

Beste regards, Gert-Jan
 
G

Gert-Jan

Hi Martin,

Thanks, but it doesn't work. When I remove the error line, I will get an
error.

Regards, Gert-Jan
 
G

Gert-Jan

This works fine:

Sub DelDups_TwoLists()
Dim iListCount As Integer
Dim iCtr As Integer
Application.ScreenUpdating = False
iListCount = Sheets("sheet1").Range("A1:A100").Rows.Count
For Each x In Sheets("Sheet2").Range("A1:A100")
For iCtr = 1 To iListCount
If x.Value = Sheets("Sheet1").Cells(iCtr, 1).Value Then
Sheets("Sheet1").Cells(iCtr, 1).Delete xlShiftUp
iCtr = iCtr + 1
End If
Next iCtr
Next
Application.ScreenUpdating = True
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top