Sub yy()
'by:Zamyi
Dim d As New Dictionary, R
Dim k, i, j
R = Sheet1.[a1].CurrentRegion
k = 1
For i = 2 To UBound(R)
R(i, 2) = Replace(Replace(R(i, 2), "(", "("), ")", ")")
If d.Exists(R(i, 2)) And d(R(i, 2)) <> "" Then ‘此处加d(R(i, 2)) <> "" 判断
R(d(R(i, 2)), 1) = R(d(R(i, 2)), 1) & " " & R(i, 1)
R(d(R(i, 2)), 4) = R(d(R(i, 2)), 4) & " " & R(i, 4)
R(d(R(i, 2)), 5) = Val(R(d(R(i, 2)), 5)) + R(i, 5)
R(d(R(i, 2)), 6) = Val(R(d(R(i, 2)), 6)) + R(i, 6)
Else
k = k + 1
d(R(i, 2)) =k ’此处原为 d(R(i,2))=i
For j = 1 To UBound(R, 2)
R(k, j) = R(i, j)
Next
End If
Next
With Sheet2
.Cells.ClearContents
.Cells.Borders.LineStyle = xlNone
.[a1:F1].Resize(d.Count + 1) = R
.[a1:F1].Resize(d.Count + 1).Borders.LineStyle = 1
End With
Set d = Nothing
End Sub |