|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
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
‘’‘’‘’结果排序
|
|