|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
- Sub test() 'VX:longwuVBA
- Dim lastRow, Arr, Brr(), Dic, Dic1, Dic2, key
- Set Dic = CreateObject("scripting.dictionary")
- Set Dic1 = CreateObject("scripting.dictionary")
- Set Dic2 = CreateObject("scripting.dictionary")
- lastRow = Sheet1.Cells(Rows.Count, 1).End(3).Row
- Arr = Sheet1.Range("A2:F" & lastRow)
- For i = 1 To UBound(Arr)
- If Not Dic1.exists(Arr(i, 5)) Then
- l = l + 1
- Dic1(Arr(i, 5)) = l
- End If
- If Arr(i, 4) <> 4 Then
- key = Arr(i, 2) & "|" & Arr(i, 3) & "|" & Arr(i, 4) & "|" & Arr(i, 5)
- If Not Dic.exists(key) Then
- k = k + 1
- Dic(key) = k
- End If
- Dic2(key) = Dic2(key) + Arr(i, 6)
- End If
- Next
- dickey = Dic.keys
- dickey1 = Dic1.keys
- ReDim Brr(1 To 10000, 1 To 10)
- For i = 1 To Dic.Count
- temp = Split(dickey(i - 1), "|")
- Brr(Dic(dickey(i - 1)), Dic1(temp(3)) + 3) = Brr(Dic(dickey(i - 1)), Dic1(temp(3)) + 3) + Dic2(dickey(i - 1))
- Brr(Dic(dickey(i - 1)), 1) = temp(0)
- Brr(Dic(dickey(i - 1)), 2) = temp(1)
- Brr(Dic(dickey(i - 1)), 3) = temp(2)
- Next
- Range("H2").Resize(Dic.Count, Dic1.Count + 3) = Brr
- End Sub
复制代码 |
|