|
参与一下。。。- Sub ykcbf() '//2024.2.20
- Dim arr, brr, crr
- Set d = CreateObject("Scripting.Dictionary")
- Set d1 = CreateObject("Scripting.Dictionary")
- Application.ScreenUpdating = False
- Set ws = ThisWorkbook
- Set sh = ws.Sheets("数据统计")
- With sh
- rq1 = CLng(DateValue(.[b1]))
- rq2 = CLng(DateValue(.[b2]))
- End With
- With ws.Sheets("出入库台账")
- r = .Cells(Rows.Count, 1).End(3).Row
- arr = .Range("a1:j" & r)
- End With
- ReDim brr(1 To UBound(arr), 1 To 8)
- ReDim crr(1 To UBound(arr), 1 To 8)
- On Error Resume Next
- For i = 2 To UBound(arr)
- s = arr(i, 1) & "|" & arr(i, 2) & "|" & arr(i, 3)
- rq = CLng(arr(i, 4))
- If rq >= rq1 And rq <= rq2 Then
- If Not d.exists(s) Then
- m = m + 1
- d(s) = m
- brr(m, 1) = arr(i, 1)
- brr(m, 2) = arr(i, 2)
- brr(m, 3) = arr(i, 3)
- For j = 5 To 9
- brr(m, j) = arr(i, j)
- Next
- Else
- r = d(s)
- brr(r, j) = brr(r, j) + arr(i, j)
- End If
- If Not d1.exists(s) Then
- n = n + 1
- d1(s) = n
- crr(n, 1) = arr(i, 1)
- crr(n, 2) = arr(i, 2)
- crr(n, 3) = arr(i, 3)
- For j = 5 To 9
- crr(n, j) = arr(i, j)
- Next
- Else
- r = d1(s)
- crr(r, j) = crr(r, j) + arr(i, j)
- End If
- End If
- Next
- With ws.Sheets("日期统计")
- .UsedRange.Offset(1).Clear
- With .[a2].Resize(m, 8)
- .Value = brr
- .Borders.LineStyle = 1
- .HorizontalAlignment = xlCenter
- .VerticalAlignment = xlCenter
- End With
- End With
- With ws.Sheets("商品名称统计")
- .UsedRange.Offset(1).Clear
- With .[a2].Resize(n, 8)
- .Value = crr
- .Borders.LineStyle = 1
- .HorizontalAlignment = xlCenter
- .VerticalAlignment = xlCenter
- End With
- End With
- Application.ScreenUpdating = True
- MsgBox "OK!"
- End Sub
复制代码
|
|