you can do it in VBA but I don't know how to do it with formulae unless the number of lines of data and types of data are quite limited.