|
我记得回过你几贴子的,详见附件及代码
- Sub Lkyy()
- Dim T_star, T_end, i%, t$, s%, R_inc%, R_exp%
- qcz = Sheets("期初值").[c2]
- T_star = [c4]
- T_end = [c5]
- Set d_inc = CreateObject("Scripting.Dictionary") '收入
- Set d_exp = CreateObject("Scripting.Dictionary") '支出
- Application.ScreenUpdating = False
- Application.DisplayAlerts = False
- With Sheet11
- '.Range("a1").CurrentRegion.Sort "日期", xlAscending, Header:=xlYes
- ar = .Range("a1").CurrentRegion
- For i = 2 To UBound(ar)
- If ar(i, 1) >= T_star And ar(i, 1) <= T_end Then
- t = ar(i, 9) & "," & ar(i, 10)
- If Len(ar(i, 24)) Then d_inc(t) = d_inc(t) + ar(i, 24)
- If Len(ar(i, 25)) Then d_exp(t) = d_exp(t) + ar(i, 25)
- End If
- If T_star > ar(i, 1) Then
- s = s + ar(i, 24) - ar(i, 25)
- End If
- Next
- End With
- Range("b11:h30,c6:c7").ClearContents
- [c6] = s + qcz
- Range("b11").Resize(d_inc.Count, 1) = Application.Transpose(d_inc.keys)
- Range("b11").Resize(d_inc.Count, 1).TextToColumns comma:=True
- Range("d11").Resize(d_inc.Count, 1) = Application.Transpose(d_inc.items)
- Range("f11").Resize(d_exp.Count, 1) = Application.Transpose(d_exp.keys)
- Range("f11").Resize(d_exp.Count, 1).TextToColumns comma:=True
- Range("h11").Resize(d_exp.Count, 1) = Application.Transpose(d_exp.items)
- R_inc = Range("b10").End(xlDown).Row
- R_exp = Range("f10").End(xlDown).Row
- Range("b" & R_inc + 1) = "合计"
- Range("f" & R_exp + 1) = "合计"
- Range("d" & R_inc + 1).Formula = "=sum(" & Range("d11:d" & R_inc).Address(0, 0) & ")"
- Range("h" & R_exp + 1).Formula = "=sum(" & Range("h11:h" & R_exp).Address(0, 0) & ")"
- [c7] = Range("d" & R_inc + 1) - Range("h" & R_exp + 1) + [c6]
- Application.DisplayAlerts = True
- Application.ScreenUpdating = True
- Set d_inc = Nothing
- Set d_exp = Nothing
- End Sub
复制代码
|
评分
-
1
查看全部评分
-
|