Merging rows in a column based on the dynamic count of a Pivot table

  Kiến thức lập trình

I am trying to write a macro that merges rows in a column to match the count of pivot table group. For example: I have three companies in Col A and each company has a different number of invoices (listed vertically) in Col B. I need to be able to merge and center the rows in a column to match the number of invoices per company.It would need to be dynamic as the number of invoices and companies changes regularly. Any ideas?

I have attached an example of what the end result should look like. End result