I had a similar issue in a macro that I was running. The reason it worked when I stepped through was that it was slowed down. The macro was running faster than the flags I was looking for. I added a delay in the code and it worked. Try adding a delay to see if that works.