|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
- Sub test()
- Dim r%, i%
- Dim arr, brr
- With Worksheets("查询")
- xm = .Range("c6")
- ReDim brr(1 To 13, 1 To 3)
- For i = 1 To UBound(brr) - 1
- brr(i, 1) = i
- Next
- brr(13, 1) = "合计"
- End With
- For k = 1 To 12
- With Worksheets(k & "月")
- n = 1
- For j = 2 To 5 Step 3
- n = n + 1
- r = .Cells(.Rows.Count, j).End(xlUp).Row
- arr = .Cells(3, j).Resize(r, 2)
- For i = 1 To UBound(arr)
- If arr(i, 1) = xm Then
- brr(k, n) = brr(k, n) + arr(i, 2)
- End If
- Next
- Next
- End With
- Next
- For j = 2 To 3
- For i = 1 To 12
- brr(13, j) = brr(13, j) + brr(i, j)
- Next
- Next
- With Worksheets("查询")
- .Range("c8").Resize(UBound(brr), UBound(brr, 2)) = brr
- End With
- End Sub
复制代码 |
|