Listing Calculating the Loan Payments Using the Loan Object

Sub Test1LoanObject() Dim rg As Range Dim objLoan As Loan

Set rg = ThisWorkbook.WorksheetsC'Loans"). _

Range("LoanListStart").Offset(1, 0) Set objLoan = New Loan

Do Until IsEmpty(rg) With objLoan

.Term = rg.Offset(0, 1).Value .InterestRate = rg.Offset(0, 2).Value .PrincipalAmount = rg.Offset(0, 3).Value rg.Offset(0, 4).Value = .Payment End With


Set objLoan = Nothing Set rg = Nothing End Sub

This listing loops through the list of loans until it comes across an empty cell. For each loan, it reads in the various loan values and assigns them to the appropriate loan property. The loan payment is calculated and written to the worksheet before moving on to the next loan.

Listing 11.5 presents a procedure that duplicates the functionality found in Listing 11.4 except that it doesn't use the Loan object. For the purposes of this example, the only functionality that you really need to replace is the Payment function.

0 0

Post a comment