With all these suggestions and questions, I conclude that I need to rethink the logic of my scketch. But I was intrigued by the fact that with the first code from post # 2 I got the result I wanted and with the second code I could not, and they seem to do the same thing exactly