What you have programmed delivers the desired result.
However it is ineffective: you go back and forth between sheets and that is never necessary.