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 "本筆已錄入"
不容質(zhì)疑我的代碼是否正確,絕對運行正常(我編程14年以上,熟練)效果如下: