- Sub jaofuan()
- Dim d As Object, ar, br, row As Long, x As Long
- Set d = CreateObject("scripting.dictionary")
- row = ActiveSheet.Cells(Rows.Count, 1).End(xlUp).row
- ar = ActiveSheet.Range("A3:C" & row)
- ReDim br(1 To row, 1 To 3)
- For i = 1 To UBound(ar)
- If ar(i, 1) <> "" Then
- If Not d.exists(ar(i, 1) & ar(i, 3)) Then
- x = x + 1
- d(ar(i, 1) & ar(i, 3)) = x
- br(x, 1) = ar(i, 1)
- br(x, 2) = ar(i, 2)
- br(x, 3) = ar(i, 3)
- Else
- br(d(ar(i, 1) & ar(i, 3)), 2) = br(d(ar(i, 1) & ar(i, 3)), 2) + ar(i, 2)
- End If
- End If
- Next
- ActiveSheet.Range("E3").Resize(row, 3) = br
- End Sub
复制代码 |