Thanks pb71. Your first example you sent was perfect and has solved the problem for me. I'd been trying to work that out for ages.
Plus thanks for the hint about a pivot table. Cheers.