Hi mdmackillop,

Thanks for your help. i found out the the original codes are ok, the function works ,there was a mistake i made when implementing the function,lol. however, according to my original coding, i spotted a problem, which is that the function doesnt work when two or matrix value are the same. i think in the if statement, i need to make modification. any suggestions?

please see the attachment.