10a Vbafunctions
10a Vbafunctions
Open Excel
Tick Developer
Click OK
Functions
Excel uses functions to do most calculations
=SUM(x) =COUNTIF(x,y) =VLOOKUP(x,y,z)
They take an input value e.g. x, y, z then perform a calculation and return a result We can write our own functions in Visual Basic
Area of a rectangle
We want to be able to type in a function such as =RectangleArea(Height, Width) Excel should do the following calculation Area = Height * Width Excel should then give us the result
Type
This means Excel asks you for Height and Width It will then do calculations with these variables
Click Save
Click OK
Click OK
You can also use this function by typing into the cell directly
Click cell B1
Type
Challenge
Create a function which will calculate the price of a share using the Dividend Growth model You want a user to be able to use a function where they get the price by typing in a function such as:
=DGMPrice (Dividend, InterestRate, GrowthRate)
Excel should then do the following calculation and return the result
DGMPrice = Dividend / (InterestRate GrowthRate)
What is the fair price of a share if it has a dividend of 2, interest rate of 0.06, and growth rate of 0.02?