|There is no formula that will do what you want. It will require VBA code i.e. a macro.|
That said, I'm not exactly sure what you are trying to do. You've posted some example data...why not explain what you are looking for by referring to that example using row numbers to explain your desired results.
BTW...please click on the following line and read the instructions on how to post data in this forum.
Click Here Before Posting Data or VBA Code ---> How To Post Data or Code.