See attached file where I added this macro. I hope it can help you.
Sub Macro1()
Dim sh1 As Worksheet
Dim sh2 As Worksheet
Dim lastRow As Long, r As Long
Dim dic As Object, myKey As String
Dim rangeToDel As Range
On Error GoTo lblError
Set dic = CreateObject("scripting.dictionary")
Set sh1 = ThisWorkbook.Sheets("1")
Set sh2 = ThisWorkbook.Sheets("2")
lastRow = sh1.Cells(Rows.Count, "a").End(xlUp).Row
For r = 1 To lastRow
myKey = Replace(sh1.Cells(r, "a"), " ", "")
If Not dic.exists(myKey) Then
dic.Add Item:="", key:=myKey
End If
Next r
lastRow = sh2.Cells(Rows.Count, "a").End(xlUp).Row
For r = 2 To lastRow
myKey = Replace(sh2.Cells(r, "a"), " ", "")
If dic.exists(myKey) Then
If rangeToDel Is Nothing Then
Set rangeToDel = sh2.Cells(r, "a")
Else
Set rangeToDel = Union(rangeToDel, sh2.Cells(r, "a"))
End If
End If
Next r
rangeToDel.EntireRow.Delete
lblExit:
Set rangeToDel = Nothing
Set sh1 = Nothing
Set sh2 = Nothing
Set dic = Nothing
Exit Sub
lblError:
'Resume lblExit
MsgBox ("Error: " & Err.Number & " - " & Err.Description)
Resume lblExit
End Sub
Regards,
Antonio
Bookmarks