|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
供参考
- Sub test1()
- Dim Dic, Arr, Brr()
- Set Dic = CreateObject("scripting.dictionary")
- Application.ScreenUpdating = False
- Arr = Sheets("数据表").[a1].CurrentRegion
- ReDim Brr(1 To UBound(Arr), 1 To 10)
- For i = 2 To UBound(Arr)
- rq = DateValue(Arr(i, 1))
- If Not Dic.exists(rq) Then
- Set Dic(rq) = CreateObject("scripting.dictionary")
- End If
-
- If Not Dic(rq).exists(Arr(i, 3)) Then
- Set Dic(rq)(Arr(i, 3)) = CreateObject("scripting.dictionary")
- End If
- Dic(rq)(Arr(i, 3))(Arr(i, 2)) = Dic(rq)(Arr(i, 3))(Arr(i, 2)) + Arr(i, 5)
- Next i
- With Sheets("VBA查询")
- rq = DateValue(.Cells(1, 1))
- If Dic.exists(rq) Then
- For Each k In Dic(rq).keys
- x = x + 1
- Brr(x, 6) = k
- For i = 2 To UBound(Arr)
- If DateValue(Arr(i, 1)) = rq And Arr(i, 3) = k Then
- s = s + 1
- End If
- Next i
- Brr(x, 4) = s: s = 0
- For Each k1 In Dic(rq)(k).keys
- Brr(x, 1) = Join(Dic(rq)(k).keys, "/")
- Brr(x, 3) = Join(Dic(rq)(k).items, "/")
- Next
- Next
- End If
- For i = 1 To x
- If InStr(Brr(i, 3), "/") Then
- For n = 0 To UBound(Split(Brr(i, 3), "/"))
- pj = Val(Split(Brr(i, 3), "/")(n)) \ Brr(i, 4)
- mm = mm & "/" & pj
- Next n
- Brr(i, 5) = Right(mm, Len(mm) - 1): mm = ""
- Else
- Brr(i, 5) = Brr(i, 3) \ Brr(i, 4)
- End If
- Next i
- .[a3:f999].ClearContents
- .[a3].Resize(x, 6) = Brr
- .Activate
- End With
- Set Dic = Nothing
- Application.ScreenUpdating = True
- End Sub
复制代码 |
|