Hello
Looking for some help modifying this code which compares and copies data. The current code compares a list on one “Sheet (A), Column A”; with a list of values on another “Sheet (COMPARE), Column A”. Any value in the list on Sheet (COMPARE), Column A that is not listed on Sheet (A), Column A is copied to the last row on Sheet (A) along with two adjacent columns, Sheet (COMPARE), Columns B & C.
I would like to revise this to do the same thing but instead of comparing values in Column A, it compares the values in Column B on both sheets; “Sheet (A), Column B” and “Sheet (COMPARE), Column B”.
Seems like a simple change - but just cant seem to get something to work. Appreciate the Help. Thanks.
Looking for some help modifying this code which compares and copies data. The current code compares a list on one “Sheet (A), Column A”; with a list of values on another “Sheet (COMPARE), Column A”. Any value in the list on Sheet (COMPARE), Column A that is not listed on Sheet (A), Column A is copied to the last row on Sheet (A) along with two adjacent columns, Sheet (COMPARE), Columns B & C.
I would like to revise this to do the same thing but instead of comparing values in Column A, it compares the values in Column B on both sheets; “Sheet (A), Column B” and “Sheet (COMPARE), Column B”.
Seems like a simple change - but just cant seem to get something to work. Appreciate the Help. Thanks.
VBA Code:
Sub test()
With Worksheets("Compare")
lastrow = .Cells(Rows.Count, "A").End(xlUp).Row
compar = .Range(.Cells(1, 1), .Cells(lastrow, 3))
End With
Worksheets("A").Select
lastdata = Cells(Rows.Count, "A").End(xlUp).Row
datar = Range(Cells(1, 1), Cells(lastdata, 1))
indi = lastdata + 1
For j = 1 To lastrow
For i = 1 To lastdata
fnd = False
If datar(i, 1) = compar(j, 1) Then
' name found
fnd = True
Exit For
End If
Next i
If Not (fnd) Then
For kk = 1 To 3
Cells(indi, kk) = compar(j, kk)
Next kk
indi = indi + 1
End If
Next j
End Sub