答案 0 :(得分:0)
希望这是你想要的:
Sub QuickCombine()
Dim X()
Dim Y()
Dim objDic As Object
Dim lngRow As Long
Dim lngCol As Long
Dim ws As Worksheet
X = Range([a1], Cells(Rows.Count, "G").End(xlUp))
Y = X
Set objDic = CreateObject("scripting.dictionary")
For lngRow = 1 To UBound(X, 1)
If Not objDic.exists(LCase$(X(lngRow, 1) & X(lngRow, 2))) Then
objDic.Add LCase$(X(lngRow, 1) & X(lngRow, 2)), lngRow
Else
Y(lngRow, 1) = vbNullString
Y(objDic.Item(LCase$(X(lngRow, 1) & X(lngRow, 2))), 3) = Y(objDic.Item(LCase$(X(lngRow, 1) & X(lngRow, 2))), 3) & "," & X(lngRow, 3)
End If
Next
Set ws = Sheets.Add
[a1].Resize(UBound(X, 1), UBound(X, 2)) = Y
Columns("A").SpecialCells(xlBlanks).EntireRow.Delete
End Sub
来自here。