Hi all,
I'm looking to compare surname and first name columns in one worksheet with surname and first name columns in another sheet. If there is a match it's deleted from the first file only. The user enters the range of data to be inputted.
So far i've been able to work on one column but i'm struggling to work with 2. Any help is appreciated. My code is below.
Sub Compare()
Dim Range1 As Range, Range2 As Range, Rng1 As Range, Rng2 As Range, outRng As Range
Set Range1 = Application.Selection
Set Range1 = Application.InputBox("Range1 :", Type:=8)
Set Range2 = Application.InputBox("Range2:", Type:=8)
Application.ScreenUpdating = False
For Each Rng1 In Range1
xValue = Rng1.Value
For Each Rng2 In Range2
If xValue = Rng2.Value Then
If outRng Is Nothing Then
Set outRng = Rng1
Else
Set outRng = Application.Union(outRng, Rng1)
End If
End If
Next
Next
outRng.EntireRow.Delete
Application.ScreenUpdating = True
End Sub
I'm looking to compare surname and first name columns in one worksheet with surname and first name columns in another sheet. If there is a match it's deleted from the first file only. The user enters the range of data to be inputted.
So far i've been able to work on one column but i'm struggling to work with 2. Any help is appreciated. My code is below.
Sub Compare()
Dim Range1 As Range, Range2 As Range, Rng1 As Range, Rng2 As Range, outRng As Range
Set Range1 = Application.Selection
Set Range1 = Application.InputBox("Range1 :", Type:=8)
Set Range2 = Application.InputBox("Range2:", Type:=8)
Application.ScreenUpdating = False
For Each Rng1 In Range1
xValue = Rng1.Value
For Each Rng2 In Range2
If xValue = Rng2.Value Then
If outRng Is Nothing Then
Set outRng = Rng1
Else
Set outRng = Application.Union(outRng, Rng1)
End If
End If
Next
Next
outRng.EntireRow.Delete
Application.ScreenUpdating = True
End Sub
Last edited: