|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
只需加入工作即可:
Sub a()
Dim 字典
Set 字典 = CreateObject("Scripting.Dictionary")
With Sheet2
i = 2
Do While .Range("A" & i) <> ""
Key = .Range("A" & i)
If 字典.exists(Key) Then
字典.Item(Key) = 字典.Item(Key) + .Range("B" & i).Value
Else
字典.Add Key, .Range("B" & i).Value
End If
i = i + 1
Loop
End With
With Sheet1
字典条数 = 字典.Count
If 字典条数 > 0 Then
arr1 = 字典.Keys()
arr2 = 字典.items()
.Range(.Cells(2, 1), .Cells(字典条数 + 5, 1)) = Excel.Application.Transpose(arr1)
.Range(.Cells(2, 2), .Cells(字典条数 + 5, 2)) = Excel.Application.Transpose(arr2)
End If
End With
End Sub |
|