Excel VBA Lesson 10: Financial Functions

<<Lesson 9>> [Contents] <<Lesson 11>>

Excel VBA offers a number of financial functions that can be used for accounting and financial calculations. In this lesson, we shall deal some of those functions
that perform basic financial calculations. They are PV, FV and Pmt.

10.1 PV

PV returns the present value of a certain amount of money a person needs to invest in order to earn a certain amount of money in the future(future value),
based on the interest rate and the number of years this amount of money is kept. Additionally, it can also return the present value of an annuity which means the present value of a series of payments in
the future

The syntax of PV in Excel VBA is

PV(Rate, Nper, Pmt, FV, Due)

The parameters in the parentheses are explained below:

Rate – Interest rate per period
Nper – Number of payment periods
Pmt – Amount of periodic payment for an annuity
FV – Future value
Due – Indicates when the payment is due. Its value is 1 for beginning of month and 0 for end of the month



Example 10.1

Do you know how much you need to invest today and how much you need to save monthly in order to obtain $1,000,000 thirty years from now?
Let’assume a fixed deposit interest rate is 4% per annum and you are willing to save $100 monthly in the bank, you can write the following Excel VBA code
to find out the initial investment you need to fork out.

Private Sub CommandButton1_Click()
Dim TheRate, FuVal, Payment As Single

Dim NPeriod As Integer

TheRate = InputBox(“Enter the rate per annum”)
FuVal = InputBox(“Enter future value”)
Payment = -InputBox(“Enter amount of monthly payment”)
NPeriod = InputBox(“Enter number of years”)

MsgBox (“The Initial Investment is ” & Round(PV(TheRate / 12 / 100, NPeriod * 12, Payment, FuVal, 1), 2))
End Sub

Running the program will produce a series of input boxes where the user can enter various values. The answer is shown in Figure 10.1.
The value is negative because this is the amount you need to pay.

Figure 10.1



10.2 FV

FV returns the amount of money you will earn in future by putting in an initital investment and continue to pay certain amount periodically.
The amount is depending on the interest rate and the duration. It reflects time value of money.

The syntax of FV in Excel VBA is

FV(Rate, Nper, Pmt, PV, Due)

Example 10.2

In this example, you want to find the future value if your initial investment is $100,000, your monthly payment is $100, interest rate 5% and the investment period is 30 years

Private Sub CommandButton1_Click()

Dim TheRate, PVal, Payment As Single

Dim NPeriod As Integer

TheRate = InputBox(“Enter the rate per annum”)
PVal = InputBox(“Enter initial investment amount)
Payment = -InputBox(“Enter amount of monthly payment”)
NPeriod = InputBox(“Enter number of years”)

MsgBox (“The Initial Investment is ” & Round(FV(TheRate / 12 / 100, NPeriod * 12, -Payment, -PVal, 0), 2))

End Sub

We place negative signs in front of Payment and Pval as you are paying out the money. Running the program will produce a series of input boxes where the user can enter various values. The answer is shown in Figure 10.2.
.

Figure 10.2

10.3 Pmt

Pmt is an Excel VBA function that returns a number of periodic payments you need to make for a certain PV and FV.

The syntax of Pmt in Excel VBA is

Pmt(Rate,Nper, PV, FV, Due)

Example 10.3

For example, you borrowed a mortgage loan of 500,000 from the bank to buy a property. You have agreed to pay back the loan in thirty years
by a monthly instalment method at an interest rate of 4% per annum. Now you need to calculate the amount of monthly payment.
In this case, Rate=4/100/12 (monthly rate), Nper=30×12=360 months,PV=500,000, FV=0 (loan settled) and due=0 as you normally paying at end of the month.

Private Sub CommandButton1_Click()

Dim TheRate, PVal As Single

Dim NPeriod As Integer

TheRate = InputBox(“Enter the rate per annum”)
PVal = InputBox(“Enter Loan Amount”)
NPeriod = InputBox(“Enter number of years”)

MsgBox (“The monthly payment is ” & Round(Pmt(TheRate / 12 / 100, NPeriod * 12, Pval, 0, 0), 2))

End Sub

Running the program will produce a series of input boxes where the user can enter various values. The answer is shown in Figure 10.3.
.The value is negative because this is the amount you need to pay

Figure 10.3

<<Lesson 9>> [Contents] <<Lesson 11>>