Compare Two Columns
Sub DataExistsInFirstOnly_Based_On_Error_Number()
On Error Resume Next
Dim Sh As Worksheet
Set Sh = ActiveWorkbook.Sheets("Sheet2")
Dim LRow As Integer
LRow = Sh.Range("C" & Rows.Count).End(xlUp).Row
If LRow > 1 Then
Sh.Range("C2:C" & LRow).ClearContents
Application.Wait (Now + TimeValue("00:00:01"))
End If
Dim StartRow As Integer
StartRow = 2
Dim Lastrow As Integer
Lastrow = Sh.Range("A" & Rows.Count).End(xlUp).Row
Dim LookupRng As Range
Set LookupRng = Sh.Range(Cells(2, 2), Cells(Lastrow, 2))
Dim R As Integer 'Loop variable
Dim Criteria As String 'Lookup Value
For R = 2 To Lastrow
Criteria = Sh.Cells(R, 1).Value
Sh.Cells(R, 3).Value = Application.WorksheetFunction.VLookup(Criteria, LookupRng, 1, 0)
If Err.Number > 0 Then
Sh.Cells(R, 3).Value = "Data Doesn't Exists"
Err.Clear 'Clear the Error
End If
Next
MsgBox "Comparision Completed"
End Sub
Sub DataExistsInSecondOnly_Based_On_Error_Number()
On Error Resume Next
Dim Sh As Worksheet
Set Sh = ActiveWorkbook.Sheets("Sheet2")
Dim LRow As Integer
LRow = Sh.Range("D" & Rows.Count).End(xlUp).Row
If LRow > 1 Then
Sh.Range("D2:D" & LRow).ClearContents
Application.Wait (Now + TimeValue("00:00:01"))
End If
Dim StartRow As Integer
StartRow = 2
Dim Lastrow As Integer
Lastrow = Sh.Range("B" & Rows.Count).End(xlUp).Row
Dim LookupRng As Range
Set LookupRng = Sh.Range(Cells(2, 1), Cells(Lastrow, 1))
Dim R As Integer 'Loop variable
Dim Criteria As String 'Lookup Value
For R = 2 To Lastrow
Criteria = Sh.Cells(R, 2).Value
Sh.Cells(R, 4).Value = Application.WorksheetFunction.VLookup(Criteria, LookupRng, 1, 0)
If Err.Number > 0 Then
Sh.Cells(R, 4).Value = "Data Doesn't Exists"
Err.Clear 'Clear the Error
End If
Next
MsgBox "Comparision Completed"
End Sub