|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
- Sub test4()
- Dim r%, i%
- Dim arr, brr
- Dim d As Object
- Set d1 = CreateObject("scripting.dictionary")
- Set d2 = CreateObject("scripting.dictionary")
- With Worksheets("sheet1")
- r = .Cells(.Rows.Count, 1).End(xlUp).Row
- arr = .Range("a2:g" & r)
- For i = 2 To UBound(arr)
- d1(arr(i, 1)) = i
- Next
- For j = 2 To UBound(arr, 2)
- d2(arr(1, j)) = j
- Next
- End With
- For Each ws In Worksheets
- If d1.exists(ws.Name) Then
- m = d1(ws.Name)
- With ws
- r = .Cells(.Rows.Count, 2).End(xlUp).Row
- brr = .Range("a2:c" & r)
- s = 0
- For i = UBound(brr) To 1 Step -1
- If brr(i, 2) = "小计" Then
- s = s + brr(i, 3)
- End If
- If Len(brr(i, 1)) <> 0 Then
- If d2.exists(brr(i, 1)) Then
- n = d2(brr(i, 1))
- arr(m, n) = s
- End If
- s = 0
- End If
- Next
- End With
- End If
- Next
- With Worksheets("sheet1")
- .Range("a2").Resize(UBound(arr), UBound(arr, 2)) = arr
- End With
- End Sub
复制代码 |
评分
-
1
查看全部评分
-
|