2014-02-10 38 views

回答

5

您可以使用辅助柱这样做:

  1. 插入过滤器和排序的名字:

    enter image description here

  2. 在C2单元格,放公式:

    =IF(A2=A3,0,1) 
    

    enter image description here

    0会里的“副本”将和1会里的最后一行,以保持会。

  3. 在单元格D2,放B2的值,在D3,把下面的公式:

    =IF(A3=A2,D2&", "&B3,B3) 
    

    enter image description here

  4. 既然这样做了,复制并在列d糊值(复制整列,使用特殊粘贴并选择'值')。取下过滤器,加回过滤器,但这次在全部4列和C列上0过滤:

    enter image description here

  5. 删除这些行并清除过滤器。最后,排序列A:

    enter image description here

现在,您可以删除列B和C.

1

如果你不介意的话,你的VBA可以使用以下:

Sub ConcatRows() 
Dim arr As Variant 
Dim i As Long 
Dim d As Dictionary 

'Create a dictionary to hold all Name and Skill Values 
Set d = CreateObject("Scripting.Dictionary") 

'Fill an array with all Values 
arr = Range("A2", Cells(Rows.Count, 2).End(xlUp)) 

'Loop the Values and and them into a dictionary 
For i = LBound(arr) To UBound(arr) 

    'If Name already in list then Add Skill to Item value of Name Key 
    If d.Exists(arr(i, 1)) Then 
     d(arr(i, 1)) = d(arr(i, 1)) & ", " & arr(i, 2) 
    'If Name isn't already in list then add name with its first Skill 
    Else 
     d.Add arr(i, 1), arr(i, 2) 
    End If 

Next i 

'Write all Name back to Worksheet 
Range("A2").Resize(d.Count) = Application.Transpose(d.Keys) 
'Write all Skills Back to worksheet 
Range("B2").Resize(d.Count) = Application.Transpose(d.Items) 
End Sub