I have a code that takes two sheets, compares them, and outputs the matches to another sheet. The code works fine but the only problem is that it outputs matches that are from any column. For example; if column A equals "Cab" in sheet 1 & column A equals "Cab" in sheet 2, it outputs the row as a match. What I'm trying to have the code do is check for a FULL ROW match, so that if every value in all columns of a row matches the entire row of the other sheet, then output those rows.
My current code:
Sub CompareSolve()
Dim i As Long
Dim j As Long
Dim n As Long
Dim ar As Variant
ar = Sheet2.Cells(10, 1).CurrentRegion.Value
With CreateObject("Scripting.Dictionary")
.CompareMode = 1
For i = 2 To UBound(ar, 1)
.Item(ar(i, 1)) = Empty
Next
ar = Sheet1.Cells(10, 1).CurrentRegion.Value
n = 1
For i = 2 To UBound(ar, 1)
If .exists(ar(i, 1)) Then
n = n + 1
For j = 1 To UBound(ar, 2)
ar(n, j) = ar(i, j)
Next j
End If
Next i
End With
Sheet3.Cells(10, 8).Resize(n, UBound(ar, 2)).Value = ar
End Sub
Any ideas on how I can modify this to work?
*EDIT:
Sub CompareSolve()
Dim arr As Variant, wsa As Worksheet, lra As Long, lca As Long
Dim brr As Variant, wsb As Worksheet, lrb As Long, lcb As Long
Set wsa = Sheets(1) 'starting sheet
With wsa
lra = .Cells(.Rows.Count, 1).End(xlUp).Row
lca = .Cells(10, .Columns.Count).End(xlToLeft).Column
arr = .Range(.Cells(10, 1), .Cells(lra, lca)).Value
End With
Set wsb = Sheets(2) 'sheet to match against
With wsb
lrb = .Cells(.Rows.Count, 1).End(xlUp).Row
lcb = .Cells(10, .Columns.Count).End(xlToLeft).Column
brr = .Range(.Cells(10, 1), .Cells(lrb, lcb)).Value
End With
If Not lca = lcb Then Exit Sub
'
Dim i As Long, j As Long, r As Long, k As Long
For r = LBound(arr) To UBound(arr)
For i = LBound(brr) To UBound(brr)
For j = 10 To lcb
If brr(i, j) = arr(r, j) Then
If j = lca Then wsa.Cells(r, lca + 1).Value = i
k = 1
Exit For 'exit j
Else
Exit For 'exit j
End If
Next j
If k = 1 Then Exit For 'exit i
Next i
k = 0
Next r
End Sub