|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
Sub tq()
arr = Sheet2.Range("S1:AA" & Sheet2.Cells(Rows.Count, "S").End(xlUp).Row)
Dim dic As Object
Set dic = CreateObject("scripting.dictionary")
For i = 3 To UBound(arr)
If arr(i, 3) <> "" Then
Key1 = arr(i, 3) & "|" & arr(i, 4)
dic(Key1) = dic(Key1) + arr(i, 5)
End If
If arr(i, 6) <> "" Then
Key2 = arr(i, 6) & "|" & arr(i, 7)
dic(Key2) = dic(Key2) + arr(i, 8)
End If
Next
keys = dic.keys
ReDim brr(1 To dic.Count, 1 To 3)
For Each r In keys
k = k + 1
brr(k, 1) = Split(r, "|")(0)
brr(k, 2) = Split(r, "|")(1)
brr(k, 3) = dic(r)
Next
Sheet1.Range("E2").Resize(10000, 3).ClearContents
Sheet1.Range("E2").Resize(k, 3) = brr
Range("E1").CurrentRegion.Sort Key1:=Columns("E"), order1:=xlAscending, _
Key2:=Columns("F"), order2:=xlAscending, Header:=xlYes
End Sub
‘’‘’‘’结果排序
|
|