|
重新写了一段。
- Sub test()
- Dim r%, i%
- Dim arr, brr
- Dim d As Object
- Dim ws As Worksheet
- Set d = CreateObject("scripting.dictionary")
- Set d_ws = CreateObject("scripting.dictionary")
- For Each ws In Worksheets
- d_ws(ws.Name) = Empty
- Next
- With Worksheets("测算两月比较")
- cs = .Range("d2")
- yf = .Range("e3:f3")
- .Range("a5:g" & .Rows.Count).ClearContents
- End With
-
- If Not d_ws.exists(yf(1, 1) & "月税") Or Not d_ws.exists(yf(1, 2) & "月税") Then
- MsgBox "相关月份数据不存在!"
- Exit Sub
- End If
-
- For k = 1 To UBound(yf, 2)
- With Worksheets(yf(1, k) & "月税")
- .AutoFilterMode = False
- r = .Cells(.Rows.Count, 1).End(xlUp).Row
- arr = .Range("a7:h" & r)
- For i = 1 To UBound(arr)
- If Not d.exists(arr(i, 4)) Then
- ReDim brr(1 To 7)
- brr(2) = arr(i, 2)
- brr(3) = arr(i, 4)
- brr(4) = arr(i, 5)
- Else
- brr = d(arr(i, 4))
- End If
- If cs = "月初" Then
- brr(4 + k) = brr(4 + k) + arr(i, 7)
- Else
- brr(4 + k) = brr(4 + k) + arr(i, 8)
- End If
- d(arr(i, 4)) = brr
- Next
- End With
- Next
- ReDim crr(1 To d.Count, 1 To 7)
- m = 0
- For Each aa In d.keys
- brr = d(aa)
- brr(7) = brr(5) - brr(6)
- m = m + 1
- crr(m, 1) = m
- For j = 2 To UBound(brr)
- crr(m, j) = brr(j)
- Next
- Next
- With Worksheets("测算两月比较")
- With .Range("a5").Resize(UBound(crr), UBound(crr, 2))
- .Value = crr
- .Borders.LineStyle = xlContinuous
- End With
- End With
-
- End Sub
复制代码 |
|