I am looking for a way to compare columns A and B in one sheet to that of column A and B in another sheet. If BOTH column A and B in the first sheet match column A and B in the second sheet - I would like to have that entire row deleted in the first sheet. The sheets are in different workbooks but moving the sheet from one to the other so that they are in the same workbook is not an issue.
The purpose of deleting rows where there is matching columns is that this is a comparison from a monthly sheet to the master sheet that will determine who is a new client. Both sheets will have the same layout just different names/data (or the same name and data) screenshot example below of what the sheet layout would look like in both sheets:
[TABLE="width: 336"]
<colgroup><col><col><col><col><col></colgroup><tbody>[TR]
[TD]First Name[/TD]
[TD]Last Name[/TD]
[TD]Phone Number[/TD]
[TD]Address[/TD]
[TD]Email[/TD]
[/TR]
[TR]
[TD]Jane[/TD]
[TD]Doe[/TD]
[TD]Data[/TD]
[TD]Data[/TD]
[TD]Data[/TD]
[/TR]
[TR]
[TD]David[/TD]
[TD]Smith[/TD]
[TD]Data[/TD]
[TD]Data[/TD]
[TD]Data[/TD]
[/TR]
[TR]
[TD]Jessica[/TD]
[TD]Roberts[/TD]
[TD]Data[/TD]
[TD]Data[/TD]
[TD]Data
[/TD]
[/TR]
[TR]
[TD]Bruce[/TD]
[TD]Wayne[/TD]
[TD]Data[/TD]
[TD]Data[/TD]
[TD]Data[/TD]
[/TR]
[TR]
[TD]Angelina[/TD]
[TD]Jolee[/TD]
[TD]Data[/TD]
[TD]Data[/TD]
[TD]Data[/TD]
[/TR]
</tbody>[/TABLE]
I have the below code but it only compares one column, and I need to compare two (there may be multiple clients with the name Jane or Smith, so I need to compare two columns)
Sub monmon()
Dim S1 As Worksheet, S2 As Worksheet, lR1 As Long, lR2 As Long, _
dRws As Range, c As Range, n As Long
Set S1 = Sheets("Random1")
Set S2 = Sheets("Sheet2")
lR1 = S1.Range("A" & Rows.Count).End(xlUp).Row
lR2 = S2.Range("A" & Rows.Count).End(xlUp).Row
Application.ScreenUpdating = False
For Each c In S1.Range("A2", "A" & lR1)
If Not IsEmpty(c) Then
n = 0
On Error Resume Next
n = Application.Match(c.Value, S2.Range("A2", "A" & lR2), 0)
On Error GoTo 0
If n > 0 Then
If Not dRws Is Nothing Then
Set dRws = Union(dRws, c.EntireRow)
Else
Set dRws = c.EntireRow
End If
End If
End If
Next c
If Not dRws Is Nothing Then dRws.Delete
Set dRws = Nothing
For Each c In S2.Range("A2", "A" & lR2)
If IsEmpty(c) Then
If Not dRws Is Nothing Then
Set dRws = Union(dRws, c.EntireRow)
Else
Set dRws = c.EntireRow
End If
End If
Next c
If Not dRws Is Nothing Then dRws.Delete
End Sub
Any help is appreciated! Thank you.
The purpose of deleting rows where there is matching columns is that this is a comparison from a monthly sheet to the master sheet that will determine who is a new client. Both sheets will have the same layout just different names/data (or the same name and data) screenshot example below of what the sheet layout would look like in both sheets:
[TABLE="width: 336"]
<colgroup><col><col><col><col><col></colgroup><tbody>[TR]
[TD]First Name[/TD]
[TD]Last Name[/TD]
[TD]Phone Number[/TD]
[TD]Address[/TD]
[TD]Email[/TD]
[/TR]
[TR]
[TD]Jane[/TD]
[TD]Doe[/TD]
[TD]Data[/TD]
[TD]Data[/TD]
[TD]Data[/TD]
[/TR]
[TR]
[TD]David[/TD]
[TD]Smith[/TD]
[TD]Data[/TD]
[TD]Data[/TD]
[TD]Data[/TD]
[/TR]
[TR]
[TD]Jessica[/TD]
[TD]Roberts[/TD]
[TD]Data[/TD]
[TD]Data[/TD]
[TD]Data
[/TD]
[/TR]
[TR]
[TD]Bruce[/TD]
[TD]Wayne[/TD]
[TD]Data[/TD]
[TD]Data[/TD]
[TD]Data[/TD]
[/TR]
[TR]
[TD]Angelina[/TD]
[TD]Jolee[/TD]
[TD]Data[/TD]
[TD]Data[/TD]
[TD]Data[/TD]
[/TR]
</tbody>[/TABLE]
I have the below code but it only compares one column, and I need to compare two (there may be multiple clients with the name Jane or Smith, so I need to compare two columns)
Sub monmon()
Dim S1 As Worksheet, S2 As Worksheet, lR1 As Long, lR2 As Long, _
dRws As Range, c As Range, n As Long
Set S1 = Sheets("Random1")
Set S2 = Sheets("Sheet2")
lR1 = S1.Range("A" & Rows.Count).End(xlUp).Row
lR2 = S2.Range("A" & Rows.Count).End(xlUp).Row
Application.ScreenUpdating = False
For Each c In S1.Range("A2", "A" & lR1)
If Not IsEmpty(c) Then
n = 0
On Error Resume Next
n = Application.Match(c.Value, S2.Range("A2", "A" & lR2), 0)
On Error GoTo 0
If n > 0 Then
If Not dRws Is Nothing Then
Set dRws = Union(dRws, c.EntireRow)
Else
Set dRws = c.EntireRow
End If
End If
End If
Next c
If Not dRws Is Nothing Then dRws.Delete
Set dRws = Nothing
For Each c In S2.Range("A2", "A" & lR2)
If IsEmpty(c) Then
If Not dRws Is Nothing Then
Set dRws = Union(dRws, c.EntireRow)
Else
Set dRws = c.EntireRow
End If
End If
Next c
If Not dRws Is Nothing Then dRws.Delete
End Sub
Any help is appreciated! Thank you.