15
15、要过程中输入如下代码:
Dim k As Integer
With ThisWorkbook.Sheets("sheet1")
If .Cells(1, 1) = "" Then
.Cells(1, 1) = "日期"
.Cells(1, 2) = "摘要"
.Cells(1, 3) = "借方"
.Cells(1, 4) = "贷方"
.Cells(1, 5) = "余额"
End If
End With
k = ThisWorkbook.Sheets("sheet1").End(xlUp).Row
With ThisWorkbook.Sheets("sheet1")
.Cells(k + 1, 1) = CDate(Me.TextBox1.Value)
.Cells(k + 1, 2) = Me.TextBox2.Value
If Me.TextBox3.Value = "收" Then
.Cells(k + 1, 3) = Val(Me.TextBox4.Value)
Else
.Cells(k + 1, 4) = Val(Me.TextBox4.Value)
End If
If k = 1 Then
.Cells(k + 1, 5) = Val(.Cells(k + 1, 3)) - Val(.Cells(k + 1, 4))
Else
.Cells(k + 1, 5) = Val(.Cells(k + 1, 3)) - Val(.Cells(k + 1, 4)) + Val(.Cells(k, 5))
End If
End With
MsgBox "本笔已录入"
不容质疑我的代码是否正确,绝对运行正常(我编程14年以上,熟练)效果如下: