dear, werafa
when i run you code, i got the error, see the screen
19-09-2018 12-11-30.jpg


also, you need to define what you need to do when you find a duplicated Value - all I did was put a comment at this place.

duplicate value put in column
to be more clearly, here simple example
makar makfa 500 makar makfa
onion onion
makfa makar circle makar makfa

makar makfa it is common pattern for row 1 and 3 so opposite it, pattern placed.

How to do it?