|
Sub 查询()
Dim T_star, T_end, Rng As Range, i%, n%, s
qcz = Sheet14.[c2]
Set d = CreateObject("scripting.dictionary")
cxx = "日期,账户名称,单据号码,摘要,收入金额,支出金额"
cxrr = Split(cxx, ",")
arr = Sheets("数据库").[a1].CurrentRegion
ReDim brr(1 To UBound(arr), 1 To UBound(cxrr) + 1)
For j = 1 To UBound(arr, 2) '表头与列号挂钩
d(arr(1, j)) = j
Next
For j = 0 To UBound(cxrr) '查询内容与源表列号挂钩
cxrr(j) = d(cxrr(j))
Next
rq1 = [h3]: rq2 = [h5]
For i = 1 To UBound(arr)
rq = arr(i, 1)
If rq >= rq1 And rq <= rq2 Then
n = n + 1
For j = 1 To UBound(brr, 2)
brr(n, j) = arr(i, cxrr(j - 1))
Next
End If
If rq1 > arr(i, 1) Then
s = s + arr(i, 23) - arr(i, 24)
End If
Next
[b8:h1000] = ""
[e8] = "期初值": [h8] = s + qcz
[b9].Resize(n, UBound(brr, 2)) = brr
myr = Range("b9").End(xlDown).Row
Range("b" & myr + 1) = "合计"
Range("f" & myr + 1).Formula = "=sum(" & Range("f9:f" & myr).Address(0, 0) & ")"
Range("g" & myr + 1).Formula = "=sum(" & Range("g9:g" & myr).Address(0, 0) & ")"
Range("h" & myr + 1) = Range("f" & myr + 1) - Range("g" & myr + 1) + [h8]
End Sub
|
|