|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
在运行如下宏时12月份不能自动生成“本月合计”及“本年累计”
其他月份倒是能生成呢。另还想增加一个宏在打印时能增加“过次页”“承前页”
Sub test()
Range("a6:m65536").ClearContents
物料编号 = Range("b2")
Set dic = CreateObject("scripting.dictionary") '本月合计
Set dic1 = CreateObject("scripting.dictionary") '本年累计
rn = Sheets(1).[a1].CurrentRegion
Rng = Sheets(1).[a1].CurrentRegion.Resize(UBound(rn) + 1, UBound(rn, 2))
TR = 5
For r = 2 To UBound(Rng)
If Rng(r, 3) = 物料编号 Or r = UBound(Rng) Then
TR = TR + 1
摘要 = Rng(r, 8)
If 摘要 = "期初余额" Then
Cells(TR, 3) = 摘要
For c = 11 To 13
Cells(TR, c) = Rng(r, c - 2) 'i -k
dic(c) = Rng(r, c - 2) '数 量 单 价 金 额
dic1(c) = Rng(r, c - 2)
Next c
Else
If (Month(Rng(r, 1)) <> m And m <> "") Then
Cells(TR, 3) = "本月合计"
For c = 4 To 9
Cells(TR, c) = dic(c)
Next c
For c = 11 To 13 '余额
Cells(TR, c) = dic(c)
Next c
If Cells(TR, 6) <> "" Then Cells(TR, 5) = "=" & Cells(TR, 6) & "/" & Cells(TR, 4)
If Cells(TR, 9) <> "" Then Cells(TR, 8) = "=" & Cells(TR, 9) & "/" & Cells(TR, 7)
If Cells(TR, 13) <> "" Then Cells(TR, 12) = "=" & Cells(TR, 13) & "/" & Cells(TR, 11)
Set dic = CreateObject("scripting.dictionary")
TR = TR + 1
Cells(TR, 3) = "本年累计"
For c = 4 To 9
Cells(TR, c) = dic1(c)
Next c
For c = 11 To 13
Cells(TR, c) = dic1(c)
Next c
If Cells(TR, 6) <> "" Then Cells(TR, 5) = "=" & Cells(TR, 6) & "/" & Cells(TR, 4)
If Cells(TR, 9) <> "" Then Cells(TR, 8) = "=" & Cells(TR, 9) & "/" & Cells(TR, 7)
If Cells(TR, 13) <> "" Then Cells(TR, 12) = "=" & Cells(TR, 13) & "/" & Cells(TR, 11)
TR = TR + 1
If r = UBound(Rng) Then GoTo LINE10:
End If
Cells(TR, 3) = 摘要
m = Month(Rng(r, 1))
Cells(TR, 1) = Rng(r, 1)
Cells(TR, 2) = Rng(r, 2)
For c = 4 To 6
dic(c) = dic(c) + Rng(r, c + 8) '****
dic1(c) = dic1(c) + Rng(r, c + 8)
Cells(TR, c) = Rng(r, c + 8)
dic(c + 7) = dic(c + 7) + Rng(r, c + 8)
dic1(c + 7) = dic1(c + 7) + Rng(r, c + 8)
Next c
For c = 7 To 9
dic(c) = dic(c) + Rng(r, c + 8)
dic1(c) = dic1(c) + Rng(r, c + 8)
Cells(TR, c) = Rng(r, c + 8)
dic(c + 4) = dic(c + 4) - Rng(r, c + 8)
dic1(c + 4) = dic1(c + 4) - Rng(r, c + 8)
Next c
For c = 11 To 13
Cells(TR, c) = dic1(c)
Next c
If Cells(TR, 6) <> "" Then Cells(TR, 5) = "=" & Cells(TR, 6) & "/" & Cells(TR, 4)
If Cells(TR, 9) <> "" Then Cells(TR, 8) = "=" & Cells(TR, 9) & "/" & Cells(TR, 7)
If Cells(TR, 13) <> "" Then Cells(TR, 12) = "=" & Cells(TR, 13) & "/" & Cells(TR, 11)
End If
End If
Next r
LINE10:
For RR = 6 To TR - 1
If Cells(RR, 13) > 0 Then
Cells(RR, 10) = "借"
ElseIf Cells(RR, 13) < 0 Then
Cells(RR, 10) = "贷"
Else
Cells(RR, 10) = "平"
End If
Next RR
End Sub
|
|