答案1
使用此代码:
Sub Merge()
Set d = CreateObject("Scripting.Dictionary")
arr = [a1].CurrentRegion
For i = 2 To UBound(arr)
If Len(arr(i, 1)) = 0 Then arr(i, 1) = arr(i - 1, 1)
If Not d.exists(arr(i, 1)) Then
d(arr(i, 1)) = arr(i, 2)
Else
d(arr(i, 1)) = d(arr(i, 1)) & "," & arr(i, 2)
End If
Next
[d2].Resize(d.Count, 2) = Application.Transpose(Array(d.keys, d.items))
End Sub