金利 8%、ローン期間 15 年、初期ローン額 £200,000 のローン テーブルを生成する必要があります。Excel 2010 で以下の VBA コードを使用しましたが、テーブルが正しく表示されません。これは私が使用したコードです。
Sub LoanSchedule()
Dim intRate, loanLife, initLoan, payment
intRate = InputBox("Input Interest rate:")
loanLife = InputBox("Input Loan life:")
initLoan = InputBox("Input Loan amount:")
Cells(4, 2).Value = intRate
Cells(5, 2).Value = loanLife
Cells(6, 2).Value = initLoan
payment = Pmt(intRate, loanLife, -initLoan)
'Year-beg Bal Annual Payment Interest Component Prinicipal Repaid Year-end Bal
Dim yearBegBal, intComp, prinComp, yearEndBal
outRow = 10
yearBegBal = LoanAmtBal
For rowNum = 1 To loanLife
intComp = yearBegBal * intRate
prinComp = payment - intComp
yearEndBal = yearBegBal - prinComp
Cells(outRow + rowNum, 1).Value = rowNum
Cells(outRow + rowNum, 2).Value = yearBegBal
Cells(outRow + rowNum, 3).Value = payment
Cells(outRow + rowNum, 4).Value = intComp
Cells(outRow + rowNum, 5).Value = prinComp
Cells(outRow + rowNum, 6).Value = yearEndBal
yearBegBal = yearEndBal
Next rowNum
End Sub
VBA初心者なのでどなたか教えてください。