replace some rows if some rows of spreadsheet are equal

i have two grouped of columns in one worksheet like below:

(before)

i want a macro do the algorithm like below:
when (code=new-code) then (code=new-code && serial=new-serial && amount=new-amount)

after macro sort table i want get below result according to algorithm:

(after)

AttachmentSize
before.xlsx9.25 KB
after.xlsx8.11 KB