2,462
社区成员
发帖
与我相关
我的任务
分享
Sub S()
Dim listweight, listpack
Set listweight = CreateObject("Scripting.Dictionary")
Set listpack = CreateObject("Scripting.Dictionary")
For i = 2 To Sheet1.UsedRange.Rows.Count
Dim id As String
Dim weight As Long
Dim packno As String
id = Sheet1.Cells(i, 1)
weight = Sheet1.Cells(i, 2)
packno = Sheet1.Cells(i, 3)
If listweight.exists(id) Then
listweight(id) = listweight(id) + weight
listpack(id) = listpack(id) & packno & ","
Else
listweight(id) = weight
listpack(id) = packno & ","
End If
Next i
i = 1
Sheet2.Cells(1, 1) = "提单号"
Sheet2.Cells(1, 2) = "总重"
Sheet2.Cells(1, 3) = "箱号"
For Each Key In listweight.keys
i = i + 1
Sheet2.Cells(i, 1) = Key
Sheet2.Cells(i, 2) = listweight.Item(Key)
Sheet2.Cells(i, 3) = Left(listpack.Item(Key), Len(listpack.Item(Key)) - 1)
Next
End Sub