Thanks for the reply. I tested the code on a copy of my data and it worked perfectly. Thanks for your help.