Hi Just to say that I have solved the second part myself with the following rather long winded code, although it did mean sorting the data differently.Thank you again to XLD for your assistance.

=IF(OR(X9<>"",B9<>B10,I9<>I8),IF(I9=I10,IF(ISERROR(IF(OR(AND(B9=B10,I9=I10,H9<>H10,I9<>I11,I10<>I8),AND(B8=B9,I8=I9,H8<>H9,I8<>I10,I9<>I7)),IF(G9="BUY",-W9,W9),"")),"",IF(OR(AND(B9=B10,I9=I10,H9<>H10,I9<>I11,I10<>I8),AND(B8=B9,I8=I9,H8<>H9,I8<>I10,I9<>I7)),IF(G9="BUY",-W9,W9),"")),IF(X9<>"","",IF(G9="BUY",-W9,W9))),IF(ISERROR(IF(OR(AND(B9=B10,I9=I10,H9<>H10,I9<>I11,I10<>I8),AND(B8=B9,I8=I9,H8<>H9,I8<>I10,I9<>I7)),IF(G9="BUY",-W9,W9),"")),"",IF(OR(AND(B9=B10,I9=I10,H9<>H10,I9<>I11,I10<>I8),AND(B8=B9,I8=I9,H8<>H9,I8<>I10,I9<>I7)),IF(G9="BUY",-W9,W9),"")))