Compare 2 Sheets of Data (Macro)
Solution 1:
Your If statement is going to return the original value of x. I think instead, you would want
If x = y Then x.Offset(0, 17) = y.Offset(0, 2)
This gives you the value found in the y column two columns to the right of the lookup.
Note that this macro is VERY slow, since it is cycling through each cell in y, even if it already found a match. If you want the first one found, then I suggest chaning your For Loop to
For Each x In Selection
For Each y In CompareRange
If x = y Then
x.Offset(0, 17) = y.Offset(0, 2)
Exit For
End If
Next y
Next x
Or better yet, just use VLOOKUP, which will do this whole function for you nicely.