|
Sub 查询()
Application.ScreenUpdating = False
Dim ar As Variant
Dim br()
Dim rn As Range
With Sheets("账户明细账查询")
zh = .[c3]
ks = .[f3]
js = .[h3]
With Sheets("明细表")
r = .Cells(Rows.Count, 2).End(xlUp).Row
ar = .Range("b1:j" & r)
Set rn = .Range("b3:d10").Find(zh, , , , , , 1)
If rn Is Nothing Then MsgBox "明细表中找不到" & zh & "信息": End
xh = rn.Row
End With
ReDim br(1 To UBound(ar) + 1, 1 To 8)
n = n + 1
br(n, 1) = "期初余额"
br(n, 8) = ar(xh, 4)
For i = 13 To UBound(ar)
If Trim(ar(i, 5)) = Trim(zh) Then
n = n + 1
For j = 2 To 8
br(n, j - 1) = ar(i, j)
Next j
br(n, 8) = br(n - 1, 8) + ar(i, 7) - ar(i, 8)
End If
Next i
If n = 1 Then MsgBox "明细表中找不到" & zh & "信息": End
n = n + 1
br(n, 1) = "合计"
For j = 6 To 8
br(n, j) = Application.Sum(Application.Index(br, 0, j))
Next j
rs = .Cells(Rows.Count, 2).End(xlUp).Row
If rs >= 6 Then .Range("a6:i" & rs) = Empty
.[b6].Resize(n, UBound(br, 2)) = br
End With
Application.ScreenUpdating = True
MsgBox "ok!"
End Sub
|
|