|
Sub 分类累计22()
Application.ScreenUpdating = False
Dim ar As Variant
Dim d As Object
Dim br()
Set d = CreateObject("scripting.dictionary")
With Sheets("原数据")
r = .Cells(Rows.Count, 1).End(xlUp).Row
If r < 2 Then MsgBox "原数据为空!": End
ar = .Range("a1:d" & r)
End With
ReDim br(1 To UBound(ar), 1 To UBound(ar) * 4)
k = 2: y = 1
For i = 2 To UBound(ar)
If Trim(ar(i, 1)) <> "" Then
t = d(Trim(ar(i, 1)))
If t = "" Then
k = k + 1
d(Trim(ar(i, 1))) = k
t = k
br(k, 1) = ar(i, 1)
End If
If Trim(ar(i, 2)) <> "" Then
If IsDate(ar(i, 2)) Then
lh = d(ar(i, 2))
If lh = "" Then
y = y + 6
d(ar(i, 2)) = y
lh = y
br(1, y - 5) = ar(i, 2)
br(2, y - 5) = "预测数量"
br(2, y - 4) = "订单数量"
br(2, y - 3) = "差异(实际-预测)"
br(2, y - 2) = "预测累计"
br(2, y - 1) = "订单累计"
br(2, y - 0) = "差异累计"
End If
br(t, lh - 5) = br(t, lh - 5) + ar(i, 3)
br(t, lh - 4) = br(t, lh - 4) + ar(i, 4)
br(t, lh - 3) = br(t, lh - 3) + ar(i, 4) - ar(i, 3)
If lh = 7 Then
br(t, lh) = br(t, lh) + br(t, lh - 5) ''差异累计
br(t, lh - 2) = br(t, lh - 2) + ar(i, 3) ''预测累计
br(t, lh - 1) = br(t, lh - 1) + ar(i, 4) ''订单累计
Else
br(t, lh) = br(t, lh - 10) + br(t, lh - 4) - br(t, lh - 5) ''差异累计
br(t, lh - 2) = br(t, lh - 2) + br(t, lh - 10) + ar(i, 3) ''预测累计
br(t, lh - 1) = br(t, lh - 1) + br(t, lh - 10) + ar(i, 4) ''订单累计
End If
End If
End If
End If
Next i
With Sheets("目标输出")
.[a1].CurrentRegion = Empty
.[a1].Resize(k, y) = br
.[a1].Resize(k, y).Borders.LineStyle = 1
End With
Set d = Nothing
Application.ScreenUpdating = True
MsgBox "ok!"
End Sub
|
|