Hi guys,
First time user here.
I'm also a beginner and here's what I need to do.
I have a workbook containing two sheets, "Sheet1" and "Sheet2", each has a column of the same type of data. I need to compare these two columns, if there's any data that match, I'd like to copy or cut it and place it in a third sheet, "Sheet3" in a column that titled "Match", and if any of the cells in Sheet1 but not Sheet2, I want to put it in the same third sheet but a different column "Sheet1Only", if anything in Sheet2 but not Sheet1, then list it in another column "Sheet2Only".
I have the code that does the first step of listing every matching cells, but I don't know how to find the ones that don't match and list them, because my code scans every possible pair and if does not match it'll copy and past it tend to generate duplicates.
Here's my code, please help:
Sub ComparePO()
Dim x As Long, y As Long, erow As Long
Dim isMatch As Boolean
Dim xLastRow As Long, yLastRow As Long
xLastRow = Worksheets("Sheet1").Cells(Rows.Count, 1).End(xlUp).Row
yLastRow = Worksheets("Sheet2").Cells(Rows.Count, 1).End(xlUp).Row
matchrow = 2
UnmatchRow = 2
For x = 2 To xLastRow
For y = 2 To yLastRow
If Worksheets("Sheet1").Cells(x, 2) = Worksheets("Sheet2").Cells(y, 4) Then
isMatch = True
Worksheets("Sheet1").Cells(x, 1).Copy Worksheets("Sheet3").Cells(matchrow, 1)
matchrow = matchrow + 1
End If
Next y
Next x
End Sub