|
Sub 统计()
Application.ScreenUpdating = False
Dim ar As Variant, br As Variant
Dim i As Long, r As Long, rs As Long
Dim cr()
Dim d As Object
Set d = CreateObject("scripting.dictionary")
With Sheets("订单明细")
r = .Cells(Rows.Count, 1).End(xlUp).Row
If r < 4 Then MsgBox "订单明细为空!": End
ar = .Range("a3:i" & r)
End With
With Sheets("月报表")
rs = .Cells(Rows.Count, 1).End(xlUp).Row
If rs < 4 Then MsgBox "月报表为空!": End
br = .Range("a3:j" & rs)
End With
ReDim cr(1 To UBound(ar), 1 To 9)
For i = 2 To UBound(ar)
If ar(i, 4) <> "" And ar(i, 5) <> "" Then
s = ar(i, 4) & "|" & ar(i, 5)
t = d(s)
If t = "" Then
k = k + 1
d(s) = k
t = k
cr(k, 1) = k
For j = 4 To 7
cr(k, j - 2) = ar(i, j)
Next j
cr(k, 9) = ar(i, 9)
End If
cr(t, 6) = cr(t, 6) + ar(i, 8)
End If
Next i
For i = 2 To UBound(br)
If br(i, 1) <> "" And br(i, 2) <> "" Then
s = br(i, 1) & "|" & br(i, 2)
xh = d(s)
If xh <> "" Then
cr(xh, 7) = br(i, 6)
cr(xh, 8) = IIf(cr(xh, 6) - cr(xh, 7) <= 0, 0, cr(xh, 6) - cr(xh, 7))
Else
cr(xh, 8) = cr(xh, 6)
End If
End If
Next i
With Sheets("订单统计")
ws = .Cells(Rows.Count, 1).End(xlUp).Row
If ws > 3 Then
.Range("a4:i" & ws).Borders.LineStyle = 0
.Range("a4:i" & ws) = Empty
End If
.[a4].Resize(k, UBound(cr, 2)) = cr
.[a4].Resize(k, UBound(cr, 2)).Borders.LineStyle = 1
End With
Application.ScreenUpdating = True
MsgBox "ok!"
End Sub
|
|