When I tried the code on some dummy data, it worked as you requested. Could you post a copy of your file? It would be easier to help I could see how your data is organized.