The minute you sell the stock you have realized your gains. It doesn't matter what you do with it later. So amount of sale, minus your cost basis {price you paid} equals taxable gain. Only other question is it short term or long term gain.
Most people are teachable, but you just can't fix stupid