|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
- Sub test()
- Dim r%, i%
- Dim arr, brr
- Dim d As Object
- Set d1 = CreateObject("scripting.dictionary")
- Set d2 = CreateObject("scripting.dictionary")
- With Worksheets("统计表")
- r = .Cells(.Rows.Count, 2).End(xlUp).Row
- .Range("h4:k" & r).ClearContents
- brr = .Range("a2:l" & r)
- For i = 3 To UBound(brr)
- xm = brr(i, 2) & "+" & brr(i, 3)
- d1(xm) = i
- Next
- For j = 8 To 11
- d2(brr(2, j)) = j
- Next
- End With
- With Worksheets("标准用量")
- r = .Cells(.Rows.Count, 2).End(xlUp).Row
- c = .Cells(2, .Columns.Count).End(xlToLeft).Column
- arr = .Range("a2").Resize(r - 1, c)
- End With
- For i = 2 To UBound(arr)
- xm = arr(i, 2) & "+" & arr(i, 3)
- If d1.exists(xm) Then
- m = d1(xm)
- For j = 8 To UBound(arr, 2)
- If d2.exists(arr(1, j)) Then
- n = d2(arr(1, j))
- brr(m, n) = brr(m, n) + arr(i, j)
- End If
- yf = Month(arr(1, j))
- If d2.exists(yf) Then
- n = d2(yf)
- brr(m, n) = brr(m, n) + arr(i, j)
- End If
- Next
- End If
- Next
- With Worksheets("统计表")
- .Range("a2").Resize(UBound(brr), UBound(brr, 2)) = brr
- End With
- End Sub
复制代码 |
|