Мне необходимо составить таблицу амортизации для фиксированного займа, где он выплачивается равными ежегодными платежами и первый платеж должен быть произведен в конце первого года.Я использую переменные процентные ставки и периоды, однако что-то не так с моим кодом, и я не уверен, что.
Я пытался зайти, но это подчеркивает многое, и я не уверен, что не так.
Это мой код:
Sub Loan_Amort_VBR()
' This version modifies the fixed rate iteration model to accommodate 3 different
' interest rates specified by the user.
Dim initLoanAmount, LoanLife
Dim yrBegBal(100), YrEndBal(), finalBal
Dim ipPay(100, 2), intRate(1 To 100)
Dim per1, per2, per3, int1, int2, int3
Dim annPayment, annPmtOld
Dim OutputRow, Rowno, NoOfIter, BalTol
Dim OutputSheet, iCol, pCol
'************************************************************
' User inputs
'************************************************************
' Read in from data entered by user on worksheet
initLoanAmount = Cells(2, 2).Value 'initial loan balance
per1 = Cells(3, 2).Value 'Length of period 1
per2 = Cells(4, 2).Value
per3 = Cells(5, 2).Value
int1 = Cells(6, 2).Value 'Interest rate for period 1
int2 = Cells(7, 2).Value
int3 = Cells(8, 2).Value
LoanLife = per1 + per2 + per3
'************************************************************
' Programmer inputs
'************************************************************
OutputSheet = "Loan Amort VBR"
BalTol = 1 'Specifies desired accuracy
iCol = 1
pCol = 2
OutputRow = 12 'row below which repayment schedule would start
'************************************************************
' Preliminaries
'************************************************************
' Make the outSheet the active sheet
Worksheets(OutputSheet).Activate
' Clear previous data
Rows(OutputRow + 1 & ":" & OutputRow + 300).Select
Selection.Clear
ReDim YrEndBal(LoanLife) 'Redimension the array
'************************************************************
' Computations and output
'************************************************************
' Enter appropriate interest rates into the intRate array
For Rowno = 1 To LoanLife
If Rowno <= per1 Then
intRate(Rowno) = int1
ElseIf Rowno <= per1 + per2 Then
intRate(Rowno) = int2
Else
intRate(rNum) = int3
End If
Next
annPayment = initLoanAmount * Application.Min(int1, int2, int3)
NoOfIter = 0 ' Counter for number of iterations
' This Do loop controls the iteration
Do While finalBal > BalTol Or finalBal = 0
' Initialize balance at the beginning of year 1
yrBegBal(1) = initLoanAmount
' Loop to calculate and store year-by-year data
For Rowno = 1 To LoanLife
ipPay(Rowno, iCol) = yrBegBal(Rowno) * intRate(Rowno)
ipPay(Rowno, pCol) = annPayment - ipPay(Rowno, iCol)
YrEndBal(Rowno) = yrBegBal(Rowno) - ipPay(Rowno, pCol)
yrBegBal(Rowno + 1) = YrEndBal(Rowno)
Next Rowno
finalBal = YrEndBal(LoanLife)
annPmtOld = annPayment
' Calculate the next annual payment to try
annPayment = annPayment + (finalBal * (1 + _
Application.Max(int1, int2, int3)) ^ _
(-LoanLife)) / LoanLife
NoOfIter = NoOfIter + 1 ' Count iterations
Loop
'***************************************************************
' Output data to worksheet
'***************************************************************
For Rowno = 1 To LoanLife
Cells(OutputRow + Rowno, 3).Value = Rowno 'Year number
Cells(OutputRow + Rowno, 4).Value = yrBegBal(Rowno)
Cells(OutputRow + Rowno, 5).Value = annPmtOld
Cells(OutputRow + Rowno, 6).Value = ipPay(Rowno, iCol)
Cells(OutputRow + Rowno, 7).Value = ipPay(Rowno, pCol)
Cells(OutputRow + Rowno, 8).Value = YrEndBal(Rowno)
Cells(OutputRow + Rowno, 9).Value = intRate(Rowno)
Next Rowno
' Print out number of iterations used
Cells(OutputRow + LoanLife + 4, 1).Value = "No. of iterations ="
Cells(OutputRow + LoanLife + 4, 2).Value = numOfIterations
'************************************************************
' Format data in table
'************************************************************
Range(Cells(OutputRow + 1, 4), Cells(OutputRow + LoanLife, 8)). _
Select
Selection.NumberFormat = "$#,##0"
Range(Cells(OutputRow + 1, 9), Cells(OutputRow + LoanLife, 9)). _
Select
Selection.NumberFormat = "0.0#%"
End Sub
Когда я вхожу в код, эти части выделяются желтым цветом:
Sub Loan_Amort_VBR()
initLoanAmount = Cells(2, 2).Value 'initial loan balance
per1 = Cells(3, 2).Value 'Length of period 1
per2 = Cells(4, 2).Value
per3 = Cells(5, 2).Value
int1 = Cells(6, 2).Value 'Interest rate for period 1
int2 = Cells(7, 2).Value
int3 = Cells(8, 2).Value
LoanLife = per1 + per2 + per3
OutputSheet = "Loan Amort VBR"
BalTol = 1 'Specifies desired accuracy
iCol = 1
pCol = 2
OutputRow = 12 'row below which repayment schedule would start
Worksheets(OutputSheet).Activate