|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
Sub test()
Set d = CreateObject("scripting.dictionary")
l = 3
Do
l1 = Cells(l, 1).End(xlDown).Row + 1
If Cells(l1 - 1, 1) = "*" Or Cells(l1 - 1, 1) = "" Then Exit Do
l2 = Cells(l, 1).End(xlDown).End(xlDown).Row - 1
arr = Range("D" & l1 & ":I" & l2)
For i = 1 To UBound(arr)
s = arr(i, 1) & "|" & arr(i, 2) & "|" & arr(i, 3)
If Not d.exists(s) Then
d(s) = Array(arr(i, 4), arr(i, 5), arr(i, 6))
Else
d(s) = Array(d(s)(0) + arr(i, 4), arr(i, 5), d(s)(2) + arr(i, 6))
End If
Next
ReDim brr(1 To d.Count, 1 To 6)
m = 0
For Each Key In d
m = m + 1
brr(m, 1) = Split(Key, "|")(0)
brr(m, 2) = Split(Key, "|")(1)
brr(m, 3) = Split(Key, "|")(2)
brr(m, 4) = d(Key)(0)
brr(m, 5) = d(Key)(1)
brr(m, 6) = d(Key)(2)
Next
Range("D" & l1 & ":I" & l1 + m - 1) = brr
If l2 > l1 + m - 1 Then
Rows(m + l1 & ":" & l2).Delete
End If
d.RemoveAll
l = l1 + m
Loop
End Sub |
评分
-
1
查看全部评分
-
|