本帖最后由 dbg111222 于 2024-2-29 10:49 编辑
我想在下面的代码中增加按照从A列的A5开始按照时间排序,排序完后增加If r > 5 Then br(r, 8) = br(r - 1, 8) + br(r, 4) - br(r, 5) - br(r, 6) + br(r, 7),最下面一行B列和J列的地方增加固定签字的地方,谢谢!
Sub 明细帐页()
ar = Sheets("库存").UsedRange
With Sheets("明细账页")
m = .Range("b2")
bm = .Range("e2")
.[h2] = ""
.[b3] = ""
.[e3] = ""
.UsedRange.Offset(4).Clear
br = .Range("a1").Resize(9999, 11)
r = 4
End With
For i = 3 To UBound(ar)
If ar(i, 2) = bm Then
br(2, 9) = ar(i, 19)
br(3, 2) = ar(i, 5)
br(3, 5) = ar(i, 4)
r = r + 1
br(r, 1) = DateSerial(Year(Now), m, 1)
br(r, 3) = ar(i, 6)
br(r, 8) = ar(i, 6)
Exit For
End If
Next
sr = Sheets("收入").UsedRange
For i = 2 To UBound(sr)
If sr(i, 2) = bm And month(sr(i, 12)) = m Then
r = r + 1
br(r, 1) = sr(i, 12)
' br(r, 2) = sr(i, 11)
br(r, 4) = sr(i, 6)
If r > 5 Then br(r, 8) = br(r - 1, 8) + sr(i, 6)
br(r, 9) = sr(i, 13)
End If
Next
fc = Sheets("发出").UsedRange
For i = 2 To UBound(fc)
If fc(i, 2) = bm And month(fc(i, 11)) = m Then
r = r + 1
br(r, 1) = fc(i, 11)
br(r, 2) = fc(i, 9) & fc(i, 10)
br(r, 5) = fc(i, 6)
br(r, 8) = br(r - 1, 8) - fc(i, 6)
br(r, 10) = fc(i, 12)
End If
Next
tl = Sheets("退料").UsedRange
For i = 2 To UBound(tl)
If tl(i, 2) = bm And month(tl(i, 11)) = m Then
r = r + 1
br(r, 1) = tl(i, 11)
' br(R, 2) = tl(i, 9)
br(r, 6) = tl(i, 6)
br(r, 8) = br(r - 1, 8) - tl(i, 6)
End If
Next
tk = Sheets("退库").UsedRange
For i = 2 To UBound(tl)
If tk(i, 2) = bm And month(tk(i, 12)) = m Then
r = r + 1
br(r, 1) = tk(i, 12)
br(r, 2) = tk(i, 10) & tk(i, 11)
br(r, 7) = tk(i, 6)
br(r, 8) = br(r - 1, 8) + tk(i, 6)
End If
Next
With Sheets("明细账页").Range("a1").Resize(r, 11)
.Value = br
.Borders.LineStyle = xlContinuous
End With
End Sub
|