Thanks for your reply, but that's not quite working as I'd hoped.

Line 5 and 6 are identical pairs to lines 2 and 3 but the other way round (BA rather than AB). Your formula has mistaken it for a different pair and created another pair_ID.