|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
- Sub test()
- Dim r%, i%
- Dim arr(), brr
- Dim d() As Object
- vs = [{"中类月",4;"小类月",6}]
- ReDim arr(1 To UBound(vs))
- ReDim d(1 To 2)
- For k = 1 To 2
- Set d(k) = CreateObject("scripting.dictionary")
- Next
- For k = 1 To UBound(vs)
- With Worksheets(vs(k, 1))
- r = .Cells(.Rows.Count, 1).End(xlUp).Row
- .Range("b3:d" & r).ClearContents
- arr(k) = .Range("a3:d" & r)
- For i = 1 To UBound(arr(k))
- If Left(arr(k)(i, 1), 1) Like "[0-9]" Then
- bm = Left(arr(k)(i, 1), vs(k, 2))
- d(k)(bm) = i
- End If
- Next
- End With
- Next
- With Worksheets("细类月")
- r = .Cells(.Rows.Count, 1).End(xlUp).Row
- brr = .Range("a3:d" & r)
- For i = 1 To UBound(brr)
- For k = 1 To UBound(vs)
- bm = Left(brr(i, 1), vs(k, 2))
- If d(k).exists(bm) Then
- m = d(k)(bm)
- For j = 2 To 4
- arr(k)(m, j) = arr(k)(m, j) + brr(i, j)
- Next
- End If
- Next
- Next
- End With
- For k = 1 To UBound(vs)
- With Worksheets(vs(k, 1))
- .Range("a3").Resize(UBound(arr(k)), UBound(arr(k), 2)) = arr(k)
- End With
- Next
- End Sub
复制代码 |
评分
-
1
查看全部评分
-
|