|
- Sub test()
- Dim r%, i%, m%
- Dim arr, brr, crr(1 To 2, 1 To 14)
- Dim d As Object
- Set d = CreateObject("scripting.dictionary")
- Set d1 = CreateObject("scripting.dictionary")
- With Worksheets("客户期初")
- r = .Cells(.Rows.Count, 1).End(xlUp).Row
- arr = .Range("a5:f" & r)
- For i = 1 To UBound(arr)
- d1(arr(i, 2)) = Array(arr(i, 1), arr(i, 3), arr(i, 4), arr(i, 5), arr(i, 6))
- Next
- End With
- With Worksheets("汇总表")
- r = .Cells(.Rows.Count, 1).End(xlUp).Row
- arr = .Range("a7:p" & r)
- End With
- For i = 1 To UBound(arr)
- yf = Month(arr(i, 1))
- If Not d.exists(arr(i, 16)) Then
- Set d(arr(i, 16)) = CreateObject("scripting.dictionary")
- End If
- If Not d(arr(i, 16)).exists(yf) Then
- Set d(arr(i, 16))(yf) = CreateObject("scripting.dictionary")
- End If
- d(arr(i, 16))(yf)(i) = Empty
- Next
- For Each aa In d.keys
- s = 1
- For Each bb In d(aa).keys
- s = s + d(aa)(bb).Count + 1
- Next
- s = s + 1
- ReDim brr(1 To s, 1 To 14)
- brr(1, 5) = "上年结存"
- If d1.exists(aa) Then
- brr(1, 12) = d1(aa)(4)
- End If
- m = 1
- crr(1, 5) = "本月合计"
- crr(2, 5) = "本年累计"
- For Each bb In d(aa).keys
- For Each cc In d(aa)(bb).keys
- m = m + 1
- For j = 1 To UBound(brr, 2)
- brr(m, j) = arr(bb, j)
- Next
- brr(m, 12) = brr(m - 1, 12) + brr(m, 10) - brr(m, 11)
- For Each y In Array(8, 10, 11)
- crr(1, y) = crr(1, y) + brr(m, y)
- crr(2, y) = crr(2, y) + brr(m, y)
- Next
- Next
- m = m + 1
- For j = 1 To UBound(crr, 2)
- brr(m, j) = crr(1, j)
- Next
- brr(m, 12) = brr(m - 1, 12)
- For Each y In Array(8, 10, 11)
- crr(1, y) = Empty
- Next
- Next
- m = m + 1
- For j = 1 To UBound(crr, 2)
- brr(m, j) = crr(2, j)
- Next
- For Each y In Array(8, 10, 11)
- crr(2, y) = Empty
- Next
- brr(m, 12) = brr(m - 1, 12)
- With Worksheets("模板")
- .Range("d4") = d1(aa)(0)
- .Range("e4") = aa
- .Range("h4") = d1(aa)(1)
- .Range("j4") = d1(aa)(2)
- .Range("l4") = d1(aa)(3)
- r = .Cells(.Rows.Count, 4).End(xlUp).Row
- If r > 7 Then
- .Rows("7:" & r - 1).Delete
- End If
- .Rows(7).Resize(UBound(brr)).Insert
- With .Range("a7").Resize(UBound(brr), UBound(brr, 2))
- .Value = brr
- .Borders.LineStyle = xlContinuous
- .Interior.ColorIndex = xlNone
- With .Font
- .ColorIndex = 0
- .Bold = False
- End With
- End With
- For i = 1 To UBound(brr)
- If brr(i, 5) = "本月合计" Or brr(i, 5) = "本年累计" Then
- With .Cells(i + 6, 1).Resize(1, 14).Borders(xlEdgeLeft)
- .LineStyle = xlContinuous
- .ColorIndex = 3
- End With
- With .Cells(i + 6, 1).Resize(1, 14).Borders(xlEdgeTop)
- .LineStyle = xlContinuous
- .ColorIndex = 3
- End With
- With .Cells(i + 6, 1).Resize(1, 14).Borders(xlEdgeBottom)
- .LineStyle = xlContinuous
- .ColorIndex = 3
- End With
- With .Cells(i + 6, 1).Resize(1, 14).Borders(xlEdgeRight)
- .LineStyle = xlContinuous
- .ColorIndex = 3
- End With
- End If
- Next
- r = .Cells(.Rows.Count, 4).End(xlUp).Row
- With .Cells(r, 1).Resize(1, 14)
- With .Borders(xlEdgeTop)
- .LineStyle = xlContinuous
- .Color = -1003520
- .TintAndShade = 0
- .Weight = xlThick
- End With
- End With
- .Copy after:=Worksheets(Worksheets.Count)
- On Error Resume Next
- Worksheets(aa).Delete
- On Error GoTo 0
- ActiveSheet.Name = aa
- End With
- Next
- End Sub
复制代码 |
|