|
楼主 |
发表于 2018-6-25 11:45
|
显示全部楼层
本帖最后由 迪云洲 于 2018-6-26 16:43 编辑
期末数据出不来?问题不知出在那?VBA代码如下:
Private Sub 明细账查询_Click()
aa = Timer
Dim arr, Arr1(), x, t, i
Dim a, b, c, d, e, f, msr, k, j, y
Application.ScreenUpdating = False
On Error Resume Next
With Sheets("数量明细账查询")
.Range("a6:k65536").Clear
For i = 1 To Sheets("设置").Range("b65536").End(xlUp).Row
If Sheets("设置").Cells(i, 2).Value = .Range("d3") Then '判断条件,对单元格输入值
.Range("i6") = Sheets("设置").Range("c" & i) '借贷方向
With Range("d6") '上年结转栏颜色
.Font.Bold = True
.Font.ColorIndex = 3
.Value = "上年结转"
End With
.Range("k3") = Sheets("设置").Range("f" & i)
.Range("k6") = Sheets("设置").Range("d" & i) '期初余额
.Range("j6") = Sheets("设置").Range("g" & i) '期初数量
.Range("m2") = Sheets("设置").Range("c" & i)
With Range("k6") '期初余额颜色
.Font.Bold = True
.Font.ColorIndex = 0
End With
End If
Next
End With
arr = Sheets("分录").Range("d4:p" & Sheets("分录").Range("J65536").End(xlUp).Row)
ReDim Arr1(1 To UBound(arr), 1 To 13)
msr = Sheets("数量明细账查询").Range("d3")
For c = 1 To UBound(arr)
If arr(c, 7) = msr Then '符合条件的记录
k = k + 1 '符合条件记录的记数器
Arr1(k, 1) = arr(c, 1)
Arr1(k, 2) = arr(c, 2)
Arr1(k, 3) = arr(c, 3)
Arr1(k, 4) = arr(c, 4)
Arr1(k, 5) = arr(c, 9)
Arr1(k, 6) = arr(c, 10)
Arr1(k, 7) = arr(c, 11)
Arr1(k, 8) = arr(c, 12)
End If
Next
Range("a7").Resize(k, 8) = Arr1
j = Val(Sheets("数量明细账查询").Range("a65536").End(xlUp).Row)
For t = 7 To j
If Cells(t, 6) > 0 Then Cells(t, 7) = ""
If Cells(t, 8) > 0 Then Cells(t, 5) = ""
Next
For t = 7 To j '计算期末余额及确认借贷方向
a = Cells(t, 6) '借方
b = Cells(t, 8) '贷方
s0 = Cells(t - 1, 10)
s1 = Cells(t, 5)
s2 = Cells(t, 7)
If Cells(3, 12) = Cells(t - 1, 9) Then f = Cells(t - 1, 11) '上期参考
If Cells(3, 12) <> Cells(t - 1, 9) Then f = -Cells(t - 1, 11) '上期参考
If Cells(3, 12).Value = "借" Then
e = a - b + f
s3 = s0 + s1 - s2
End If
If e >= "0" Then Cells(t, 9).Value = "借"
If e >= "0" Then
Cells(t, 10) = s3
Cells(t, 11) = e
End If
If e < "0" Then Cells(t, 9).Value = "贷"
If e < "0" Then
Cells(t, 10) = -s3
Cells(t, 11) = -e
End If
If Cells(3, 12).Value = "贷" Then
e = b - a + f
If e >= "0" Then Cells(t, 9).Value = "贷"
If e >= "0" Then Cells(t, 11) = e
If e < "0" Then Cells(t, 9).Value = "借"
If e < "0" Then Cells(t, 11) = -e
End If
Next
Cells(3, 12) = ""
|
-
|