loddydoddy81
New Member
- Joined
- Mar 22, 2022
- Messages
- 14
- Office Version
- 2016
- Platform
- Windows
I have the below code that is set to look at sheet1 Column A for Last Name. It then references sheet2 Column B. If it finds that Last Name, it deletes all rows with that last name.
The problem is that sometimes with my data, I have people with the same last name. So if I leave it as is, it will delete everyone with that last name, which I don't want.
What I need is to further add on to this code and have it look if the Column A in sheet1 has a matching last name per Column B of sheet2, it then looks in Column B of sheet1 for the First Name and then looks in Column C of sheet2 and if it IS a match it deletes. If it is NOT a match it keeps it.
For example if I have
sheet1
A B
Smith John
Smith Frank
and sheet2 has
B C
Smith John
It will leave Smith Frank and delete all rows with Smith John
With Sheets("sheet1")
lr = .Range("A" & Rows.Count).End(xlUp).Row
For i = lr To 1 Step -1
If IsNumeric(Application.Match(.Range("A" & i).Value, Sheets("sheet2").Columns("B"), 0)) Then .Rows(i).Delete
Next i
End With
The problem is that sometimes with my data, I have people with the same last name. So if I leave it as is, it will delete everyone with that last name, which I don't want.
What I need is to further add on to this code and have it look if the Column A in sheet1 has a matching last name per Column B of sheet2, it then looks in Column B of sheet1 for the First Name and then looks in Column C of sheet2 and if it IS a match it deletes. If it is NOT a match it keeps it.
For example if I have
sheet1
A B
Smith John
Smith Frank
and sheet2 has
B C
Smith John
It will leave Smith Frank and delete all rows with Smith John
With Sheets("sheet1")
lr = .Range("A" & Rows.Count).End(xlUp).Row
For i = lr To 1 Step -1
If IsNumeric(Application.Match(.Range("A" & i).Value, Sheets("sheet2").Columns("B"), 0)) Then .Rows(i).Delete
Next i
End With