Sub CalculateYearsToRepayBond()
Dim houseValue As Double
Dim interestRate As Double
Dim annualPayment As Double
Dim remainingBalance As Double
Dim years As Integer
Dim annualInterest As Double
' Input values
houseValue = 175000 ' House value (R)
interestRate = 0.18 ' Annual interest rate (18%)
annualPayment = 45000 ' Annual installment (R)
' Initialize variables
remainingBalance = houseValue
years = 0
' Loop until the bond is fully repaid
Do While remainingBalance > 0
years = years + 1
' Calculate annual interest
annualInterest = remainingBalance * interestRate
' Deduct annual payment from remaining balance
remainingBalance = remainingBalance + annualInterest - annualPayment
' Prevent infinite loop (if payment is less than interest)
If annualPayment <= annualInterest Then
MsgBox "The annual payment is too low to repay the bond. Increase the
payment amount."
Exit Sub
End If
Loop
' Output the result
MsgBox "It will take " & years & " years to repay the bond."
End Sub
NOTES:
How the Program Works
Inputs:
houseValue: The value of the house (R175,000).
interestRate: The annual interest rate (18% or 0.18).
annualPayment: The fixed annual installment (R45,000).
Logic:
The program simulates the repayment process year by year.
Each year, it calculates the interest on the remaining balance and subtracts the
annual payment.
The loop continues until the remaining balance is fully repaid.
Output:
A message box displays the number of years required to repay the bond.
Example Calculation
For the given inputs:
House Value: R175,000
Interest Rate: 18%
Annual Payment: R45,000
The program will calculate the number of years required to repay the bond.
How to Use the Code
Open Excel and press Alt + F11 to open the VBA editor.
Insert a new module (Insert > Module).
Copy and paste the code into the module.
Run the macro (F5 or Run > Run Sub/UserForm).
Output
If the inputs are valid, the program will display a message box like:
Copy
It will take X years to repay the bond.
Important Notes
Infinite Loop Prevention:
If the annual payment is less than the annual interest, the bond will never be
repaid. The program checks for this condition and displays a warning.
Adjustments:
You can modify the inputs (e.g., house value, interest rate, annual payment) to
calculate repayment periods for different scenarios.
Accuracy:
This program assumes fixed annual payments and interest rates. For more complex
scenarios (e.g., variable interest rates or payments), additional logic is
required.
Let me know if you need further assistance!