I think this person needs a VBA solution to their issue (and if so maybe the post moved there too).
https://www.excelforum.com/excel-for...-invoices.html
I'll be interested in seeing if anyone has a formula solution for the OP.