|
- Sub test()
- Dim r%, i%
- Dim arr, brr
- Dim ws As Worksheet
- Dim rng As Range
- Dim d As Object
- Set d = CreateObject("scripting.dictionary")
- For Each aa In Array("一层", "二层")
- With Worksheets(aa)
- For Each bb In Array("b4:q57", "s4:w24", "y4:ac24", "y27:ac47")
- arr = .Range(bb)
- For i = 4 To UBound(arr)
- For j = 2 To UBound(arr, 2) Step 5
- If Len(arr(i, j)) <> 0 Then
- If Not d.exists(aa) Then
- Set d(aa) = CreateObject("scripting.dictionary")
- End If
- If Not d(aa).exists(bb) Then
- Set d(aa)(bb) = CreateObject("scripting.dictionary")
- End If
- d(aa)(bb)(arr(i, j)) = d(aa)(bb)(arr(i, j)) + arr(i, j + 1)
- End If
- Next
- Next
- Next
- End With
- Next
- With Worksheets("数据")
- .UsedRange.Offset(1, 0).Clear
- r = 2
- For Each aa In d.keys
- For Each bb In d(aa).keys
- ReDim crr(1 To d(aa)(bb).Count, 1 To 2)
- m = 0
- For Each cc In d(aa)(bb).keys
- m = m + 1
- crr(m, 1) = cc
- crr(m, 2) = d(aa)(bb)(cc)
- Next
- With .Cells(r, 1)
- .Value = Switch(bb = "b4:q57", aa, bb = "s4:w24", "厨房间", bb = "y4:ac24", "卫生间1", bb = "y27:ac47", "卫生间2")
- .Resize(1, 2).Merge
- .Interior.ColorIndex = 15
- End With
- .Cells(r + 1, 1).Resize(UBound(crr), UBound(crr, 2)) = crr
- With .Cells(r, 1).Resize(1 + UBound(crr), 2)
- .Borders.LineStyle = xlContinuous
- .BorderAround LineStyle:=xlContinuous, Weight:=xlMedium
- With .Font
- .Name = "微软雅黑"
- .Size = 10
- End With
- End With
- r = r + 1 + UBound(crr)
- Next
- Next
- With .UsedRange
- .HorizontalAlignment = xlCenter
- .VerticalAlignment = xlCenter
- End With
- End With
- End Sub
复制代码 |
|