Yes.
If you make the loss and the gain in the same year, you can set one against the other.
The only tiny caveat is if the Revenue decided that you were trading in property, and sought to make it subject to income tax instead of CGT, but I think that is unlikely if it's a once off.
Brendan