How to automate the loan amortization schedule using VBA. Automating monthly payments is useful in many financial situations for people and companies. We first describe the manual process and then show the step by step connection with the macro code. The VBA code to automate the loan amortization schedule is now easy to understand and implement. Watch the video:
Let’s view this video on YouTube.
Here’s the complete VBA code to automate equal period payments based on a fixed rate of interest:
Sub Loan_Amortization()
‘Worksheets(“loanAmortization”).Activate
Rows(7 & “:” & 200).Clear
Dim lastRow As Long, rowNum As Long
lastRow = Sheets(“loanAmortization”).Cells.Find(What:=”*”, _
After:=Range(“A1”), _
LookAt:=xlPart, _
LookIn:=xlFormulas, _
SearchOrder:=xlByRows, _
SearchDirection:=xlPrevious, _
MatchCase:=False).Row
‘MsgBox lastRow
nextblankrow = lastRow + 1
Cells(nextblankrow, 1) = “Month”
Cells(nextblankrow, 2) = “Balance Beginning of Loan Period”
Cells(nextblankrow, 3) = “Monthly payment”
Cells(nextblankrow, 4) = “Interest Component of Monthly Payment”
Cells(nextblankrow, 5) = “Principal Component of Monthly Payment”
Cells(nextblankrow, 6) = “Month End Balance”
Columns.AutoFit
Dim intRate, initialLoanAmount, loanPeriod
Dim monthBeginBalance, monthEndBalance
Dim monthlyPayment, interestComponent, principalRepaid
intRate = Range(“B2”)
loanPeriod = Range(“B3”)
initialLoanAmount = Range(“B4”)
‘ Make sure interest rate is not greater than 12%
If intRate > 0.12 Then
MsgBox “Interest rate cannot be greater than 12%.”
Exit Sub
End If
monthlyPayment = Pmt(intRate / 12, loanPeriod, -initialLoanAmount, 0, 0)
monthBeginBalance = initialLoanAmount
For rowNum = 1 To loanPeriod
interestComponent = monthBeginBalance * (intRate / 12)
principalRepaid = monthlyPayment – interestComponent
monthEndBalance = monthBeginBalance – principalRepaid
Cells(nextblankrow + rowNum, 1) = rowNum ‘month number
Cells(nextblankrow + rowNum, 2) = monthBeginBalance
Cells(nextblankrow + rowNum, 3) = monthlyPayment
Cells(nextblankrow + rowNum, 4) = interestComponent
Cells(nextblankrow + rowNum, 5) = principalRepaid
Cells(nextblankrow + rowNum, 6) = monthEndBalance
monthBeginBalance = monthEndBalance
Next rowNum
Range(Cells(8, 2), Cells(nextblankrow + loanPeriod, 6)).NumberFormat = “$#,##0”
End Sub
Sample for download and practice: