Я бы подошел к этому иначе и использовал бы Power Query, доступный в Excel 2010 +.
Power Query как метод «Группировать по», где вы можете выбрать столбцы, которые хотите сгруппировать, - в вашем случае это будут все столбцы, кроме столбца Компания . Затем вы можете объединить столбец компании, используя перевод строки, и получить желаемый результат.
![enter image description here](https://i.stack.imgur.com/EhLGh.png)
- Add Custom Column (to split out the company names with formula:
Table.Column([Grouped],"Company")
![enter image description here](https://i.stack.imgur.com/VQAe9.png)
- Select the Double-headed arrow at the top of the custom column
- Extract values from list
- Use the line feed for the separator
#(lf)
- Close and Load to
You may have to do some custom formatting for the phone number, and also set Word Wrap for the company column.
Here is the generated MCode:
let
Source = Excel.CurrentWorkbook(){[Name="Table3"]}[Content],
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Email", type text}, {"Phone", Int64.Type}, {"First Name", type text}, {"Last Name", type text}, {"Company", type text}}),
#"Grouped Rows" = Table.Group(#"Changed Type", {"Email", "Phone", "First Name", "Last Name"}, {{"Grouped", each _, type table [Email=text, Phone=number, First Name=text, Last Name=text, Company=text]}}),
#"Added Custom" = Table.AddColumn(#"Grouped Rows", "Company", each Table.Column([Grouped],"Company")),
#"Extracted Values" = Table.TransformColumns(#"Added Custom", {"Company", each Text.Combine(List.Transform(_, Text.From), "#(lf)"), type text})
in
#"Extracted Values"
And here are the results:
введите описание изображения здесь