Macro..Compare 2 columns and return unmatched results

tea1998

New Member
Joined
Jun 7, 2006
Messages
6
I have 2 worksheets that I need to compare a column from each worksheet. If it doesn't find a match I need that offage to be placed on a separate worksheet with notation of which worksheet it came from.

Let me see if I can be more clear.

Sheet 1; Column B is comparing with Sheet 2; Column C
If Column B or C does not find it's match within one another, I want it to go to Sheet 3 and I want to know if the non-matched item was from Sheet 1 or Sheet 2.

Thanks!

Lori
 

Excel Facts

Test for Multiple Conditions in IF?
Use AND(test, test, test, test) or OR(test, test, test, ...) as the logical_test argument of IF.
I have 2 worksheets that I need to compare a column from each worksheet. If it doesn't find a match I need that offage to be placed on a separate worksheet with notation of which worksheet it came from.

Let me see if I can be more clear.

Sheet 1; Column B is comparing with Sheet 2; Column C
If Column B or C does not find it's match within one another, I want it to go to Sheet 3 and I want to know if the non-matched item was from Sheet 1 or Sheet 2.

Thanks!

Lori
try
Code:
Sub test()
Dim a, e
With Sheets("Sheet1")
     a = .Range("a1",.Range("a" & Rows.Count).End(xlUp)).Value
End With
With CreateObject("Scripting.Dictionary")
     .CompareMode = vbTextCompare
     For Each e In a, i As Long, y
          If Not IsEmpty(e) And Not .exists(e) Then .add, e, Array(e,1)
     Next
     With Sheets("Sheet2")
          a = .Range("c1",.Range("c" & Rows.Count).End(xlUp)).Value
     End With
     For Each e In a
          If Not IsEmpty(e) Then
               If Not .exists(e) Then
                    .add e, Array(e,2)
               Else
                    If .item(e)(1) = 1 Then .item(e) = Empty
               End If
          End If
     Next
     y = .items
End With
With Sheets("sheet3").Range("a1")
     .Resize(,2) = [{"Item","Sheet"}]
     With .Offset(1)
          For i = 0 To UBound(y)
               If Not IsEmpty(y(i)) Then
                    .Offset(n).Resize(,2).Value = y(i)
                    n = n + 1
               End If
          Next
     End With
End With
End Sub
 
Upvote 0

Forum statistics

Threads
1,215,562
Messages
6,125,546
Members
449,237
Latest member
Chase S

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top