Quite honestly what you are looking for may not be able to be done thru a pivot table, nor do I think a formula configuration would help.

It seems a VBA solution is required. I don't have time for a VBA solution right now, but maybe oeldere has something to offer...