Great stuff thanks both.

Mehmetcik there were some instances were this did not calculate correctly, so I have used AlKey's method which I was a bit wary of as Array formula's can be quite heavy on a large data set but it seems to work perfectly