|
- Sub test()
- Dim arr, brr
- Dim sht As Worksheet
- Dim dic, key
- Set dic = CreateObject("scripting.dictionary")
- j = 1
- For Each sht In Sheets
- If Val(sht.Name) > 0 Then 'If InStr(sht.Name, "汇总表") = 0 Then
- arr = sht.[a2].CurrentRegion 'a1改成了a2,因为你12个月的分表改成了从第二行开始的
- For x = 2 To UBound(arr)
- If Not dic.exists(arr(x, 1)) Then
- Set dic(arr(x, 1)) = CreateObject("scripting.dictionary")
- End If
- For y = 2 To 5
- dic(arr(x, 1))(arr(1, y)) = arr(x, y)
- dic(arr(x, 1))(sht.Name & Replace(arr(1, y), "本月", "")) = arr(x, y)
- Next
- Next
-
- For x = 2 To UBound(arr)
- For i = 3 To 4
- If Not dic.exists(arr(x, 1)) Then
- Set dic(arr(x, 1)) = CreateObject("scripting.dictionary")
- End If
- dic(arr(x, 1))(Replace(arr(1, i), "本月", "本年") & "合计") = dic(arr(x, 1))(Replace(arr(1, i), "本月", "本年") & "合计") + arr(x, i)
- Next
- Next
- End If
- Next
- Sheets("年度汇总表").[a2:ac1000].ClearContents
- For Each k In dic.keys
- j = j + 1
- Sheets("年度汇总表").Cells(j, 1) = k
- Next
- brr = Sheets("年度汇总表").[a1].CurrentRegion
- For m = 2 To UBound(brr)
- key = brr(m, 1)
- For n = 2 To UBound(brr, 2)
- If dic.exists(key) Then
- brr(m, n) = dic(key)(brr(1, n))
- End If
- Next
- Next
- Sheets("年度汇总表").[a1].CurrentRegion = brr
- End Sub
复制代码 |
评分
-
1
查看全部评分
-
|