|
Sub 统计()
Application.ScreenUpdating = False
Dim ar As Variant
Dim d As Object, dc As Object
Set d = CreateObject("scripting.dictionary")
lj = ThisWorkbook.Path & "\"
w = InputBox("请输入要统计的年月:", "年月", Year(Date) & Format(Month(Date) - 1, "00"))
If w = "" Then End
f = Dir(lj & "订单汇总.xlsx")
If f = "" Then MsgBox "找不到订单汇总文件!": End
Set wb = Workbooks.Open(lj & f, 0)
With wb.Worksheets("收入表")
r = .Cells(Rows.Count, 1).End(xlUp).Row
If r < 2 Then MsgBox "收入表为空!": End
ar = .Range("a1:l" & r)
End With
wb.Close False
Dim br()
ReDim br(1 To UBound(ar), 1 To 5)
k = 1
rr = Array("序号", "客户名称", "期初余额", "本期金额", "合计金额")
For j = 0 To UBound(rr)
br(k, j + 1) = rr(j)
Next j
For i = 2 To UBound(ar)
If ar(i, 2) <> "" Then
If IsDate(ar(i, 2)) Then
If ar(i, 5) <> "" And ar(i, 12) = "" Then
t = d(ar(i, 5))
If t = "" Then
k = k + 1
d(ar(i, 5)) = k
t = k
br(k, 1) = k - 1
br(k, 2) = ar(i, 5)
End If
nf = Year(ar(i, 2)) & Format(Month(ar(i, 2)), "00")
If nf < w Then
br(t, 3) = br(t, 3) + ar(i, 11)
End If
If nf = w Then
br(t, 4) = br(t, 4) + ar(i, 11)
End If
br(t, 5) = br(t, 3) + br(t, 4)
End If
End If
End If
Next i
Application.SheetsInNewWorkbook = 1
Set ww = Workbooks.Add
With ww.Worksheets(1)
.Name = w
.[a1].Resize(k, UBound(br, 2)) = br
.Cells(k + 1, 1) = "合计"
For j = 3 To 5
.Cells(k + 1, j) = Application.Sum(Application.Index(br, 0, j))
Next j
.[a1].Resize(k + 1, UBound(br, 2)).Borders.LineStyle = 1
End With
ww.SaveAs Filename:=lj & "统计表\" & w & ".xlsx"
MsgBox "ok!"
End Sub
|
评分
-
1
查看全部评分
-
|