CSV is not a good way to store the data the way you want.
You could create objects with MemberName and GroupName properties and then create a CSV file that looks like this:
MemberName,GroupName
James,Group1
Don,Group1
Carroll,Group1
Paul,Group1
Jon,Group2
Daniel,Group2
Paul,Group2
Donald,Group2
Mark,Group2
Luke,Group2
Ralph,Group3
Carroll,Group3
Or using pretty formatting
MemberName GroupName
---------- ---------
James Group1
Don Group1
Carroll Group1
Paul Group1
Jon Group2
Daniel Group2
Paul Group2
Donald Group2
Mark Group2
Luke Group2
Ralph Group3
Carroll Group3
To get column names to be the group names you would need to
- create objects that have the all the group names as properties
- each object would contain 3 unrelated people (one per group)
- when you run out of people for a given group you need to stop putting people in that group's property but still need to create a new object because at least one of the remaining groups will have a member
Ugh! I'm having a hard time explaining what it would take to format it the way you want to show it.
In any case, most of your code is excel management code or formatting and a CSV has neither of those. Perhaps it is best to keep your excel code.