Macro to take a table with one to many customers with multply invoices and creates flat files per cust with multiple invoices

I need help writing a macro that can take a table with multiple records per customer number and generate a flat file where there was a single record per customer and each of the subsequent statement records with the same customer number were placed into order columns in the worksheet.

I have attached a sample table with several customers with multiple records each.

And then there is a list of records where the looping and offsetting have created one long file for each customer #.