|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
Sub 分类汇总()
Dim ar As Variant
Dim d As Object, dc As Object
Set d = CreateObject("scripting.dictionary")
With Sheets("明细")
r = .Cells(Rows.Count, 1).End(xlUp).Row
ar = .Range("a1:m" & r)
End With
ReDim br(1 To UBound(ar), 1 To 9)
With Sheets("品种类")
ny = Format(.[i2], "yyyym")
For i = 2 To UBound(ar)
If Trim(ar(i, 6)) <> "" Then
If IsDate(ar(i, 6)) Then
If Trim(ar(i, 8)) <> "" Then
t = d(Trim(ar(i, 8)))
If t = "" Then
k = k + 1
d(Trim(ar(i, 8))) = k
t = k
br(k, 1) = ar(i, 8)
End If
If Trim(ar(i, 7)) = "销售" Then
If Format(ar(i, 6), "yyyym") = ny Then
br(t, 2) = br(t, 2) + ar(i, 10)
br(t, 3) = br(t, 3) + ar(i, 12)
End If
If Format(ar(i, 6), "yyyym") <= ny Then
br(t, 4) = br(t, 4) + ar(i, 10)
br(t, 5) = br(t, 5) + ar(i, 12)
End If
ElseIf Trim(ar(i, 7)) = "退货" Then
If Format(ar(i, 6), "yyyym") = ny Then
br(t, 6) = br(t, 6) + ar(i, 10)
br(t, 7) = br(t, 7) + ar(i, 12)
End If
If Format(ar(i, 6), "yyyym") <= ny Then
br(t, 8) = br(t, 8) + ar(i, 10)
br(t, 9) = br(t, 9) + ar(i, 12)
End If
End If
End If
End If
End If
Next i
.UsedRange.Offset(4).Borders.LineStyle = 0
.UsedRange.Offset(4) = Empty
.[a5].Resize(k, UBound(br, 2)) = br
.[a5].Resize(k, UBound(br, 2)).Borders.LineStyle = 1
End With
Set d = Nothing
MsgBox "ok!"
End Sub
|
评分
-
1
查看全部评分
-
|