Excel – 合并具有通用值的行,并将差异串联在一列中
我认为最简单的事情就是向你展示一个例子。
更改:
Customer Name | NEW YORK | ALBANY Customer Name | NEW YORK | CLINTON Customer Name | NEW YORK | COLUMBIA Customer Name | NEW YORK | DELAWARE Customer Name | NEW YORK | DUTCHESS Customer Name | VERMONT | BENNINGTON Customer Name | VERMONT | CALEDONIA Customer Name | VERMONT | CHITTENDEN Customer Name | VERMONT | ESSEX Customer Name | VERMONT | FRANKLIN
对此:
Customer Name | VERMONT | BENNINGTON,CALEDONIA,CHITTENDEN,ESSEX,FRANKLIN Customer Name | NEW YORK | ALBANY,CLINTON,COLUMBIA,DELAWARE,DUTCHESS
我也看到其他一些post,但我不认为他们正是我想要做的。
如果通过|
你的意思是分开单元格,然后macros(Excel 2007)应该做的伎俩(您的数据开始在单元格A1):
Application.ScreenUpdating = False last_row = Cells(Rows.Count, 1).End(xlUp).Row 'first: make sure data is sorted Sort.SortFields.Clear Sort.SortFields.Add Key:=Columns("A:A"), SortOn:=xlSortOnValues Sort.SortFields.Add Key:=Columns("B:B"), SortOn:=xlSortOnValues Sort.SortFields.Add Key:=Columns("C:C"), SortOn:=xlSortOnValues With Sort .SetRange Range("A1:C" & last_row) .Header = xlNo .MatchCase = False .Orientation = xlTopToBottom .SortMethod = xlPinYin .Apply End With 'then: join text until key values in two neighboring row changes myText = "" myPos = 1 For i = 1 To last_row If Cells(i, 1).Value <> Cells(i + 1, 1).Value Or Cells(i, 2).Value <> Cells(i + 1, 2).Value Then Cells(myPos, 5).Value = Cells(i, 1).Value Cells(myPos, 6).Value = Cells(i, 2).Value myText = myText & Cells(i, 3).Value Cells(myPos, 7).Value = myText myText = "" myPos = myPos + 1 Else myText = myText & Cells(i, 3).Value & "," End If Next i Application.ScreenUpdating = True MsgBox "Done"
在下面的超链接中,你会发现这个问题的解决scheme。 查找“如何将重复行合并为一个(仅保留唯一值)”部分
如何合并行对于许多情况
更新:执行任务的加载项不是免费的,但有15天的免费试用版