|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
- Sub 统计()
- Dim vData As Variant, nRow As Double
- Dim dicCode As Object, vCode As Variant
- Dim vFill As Variant, nFill As Double
- Dim dStart As Date, dEnd As Date, dDate As Date
-
- Application.ScreenUpdating = False
- Set dicCode = CreateObject("Scripting.Dictionary")
- With Sheet5
- dStart = .[E2].Value
- dEnd = .[F2].Value
-
- With .UsedRange
- vCode = .Offset(2, 1).Resize(.Rows.Count - 2, 1).Value
- End With
- ReDim vFill(1 To UBound(vCode), 1 To 4)
- For nRow = 1 To UBound(vCode)
- If Trim(vCode(nRow, 1)) <> "" Then dicCode(Trim(vCode(nRow, 1))) = nRow
- Next
-
- vData = Sheet3.UsedRange.Value
- For nRow = 1 To UBound(vData)
- If dicCode.Exists(Trim(vData(nRow, 10))) Then
- nFill = dicCode(Trim(vData(nRow, 10)))
- dDate = vData(nRow, 7)
- If dDate < dStart Then
- vFill(nFill, 1) = vFill(nFill, 1) + vData(nRow, 14) - vData(nRow, 15)
- vFill(nFill, 2) = vFill(nFill, 2) - vData(nRow, 14)
- vFill(nFill, 3) = vFill(nFill, 3) - vData(nRow, 15)
- ElseIf dDate <= dEnd Then
- vFill(nFill, 1) = vFill(nFill, 1) + 0
- vFill(nFill, 2) = vFill(nFill, 2) + vData(nRow, 14)
- vFill(nFill, 3) = vFill(nFill, 3) + vData(nRow, 15)
- End If
- vFill(nFill, 4) = vFill(nFill, 4) + vFill(nFill, 1) + vFill(nFill, 2) - vFill(nFill, 3)
- End If
- Next
- .[E3].Resize(UBound(vFill), 4) = vFill
- End With
- Application.ScreenUpdating = True
- End Sub
复制代码 |
|