|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
因为"数据库"中没有银行-对公相应的数值,但又想查询代码怎么写?
Sub 查询1()
Dim T_star, T_end, Rng As Range, i%, n%, s
rq3 = [c6]
crr = Sheets("期初值").[a1].CurrentRegion
For m = 1 To UBound(crr)
rq5 = crr(m, 2)
If rq5 = rq3 Then
qcz = crr(m, 3)
End If
Next
Set d = CreateObject("scripting.dictionary")
gxx = "日期,项目名称,单据号码,摘要,收入金额,支出金额"
gxrr = Split(gxx, ",")
arr = Sheets("数据库").[a1].CurrentRegion
ReDim brr(1 To UBound(arr), 1 To UBound(gxrr) + 1)
For j = 1 To UBound(arr, 2) '表头与列号挂钩
d(arr(1, j)) = j
Next
For j = 0 To UBound(gxrr) '查询内容与源表列号挂钩
gxrr(j) = d(gxrr(j))
Next
rq1 = [h3]: rq2 = [h5]: rq3 = [c6]
For i = 1 To UBound(arr)
rq = arr(i, 1)
rq4 = arr(i, 27)
If rq >= rq1 And rq <= rq2 And rq4 = rq3 Then
n = n + 1
For j = 1 To UBound(brr, 2)
brr(n, j) = arr(i, gxrr(j - 1))
Next
End If
If rq1 > arr(i, 1) Then
s = s + arr(i, 24) - arr(i, 25)
End If
Next
[b8:h1000] = ""
[e8] = "期初余额": [h8] = s + qcz
[b9].Resize(n, UBound(brr, 2)) = brr
[b9].Resize(n, UBound(brr, 2)).Sort [b9], 1, header:=2
myr = Range("b9").End(xlDown).Row
Range("e" & 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
|
|