Excel Functions
Part 1. Introduction
2
An Excel function is a formula or a procedure that is
performed in the Visual Basic environment, outside the Excel
spreadsheet.
3
For example, the sum of two variables can be evaluated in
an Excel spreadsheet as follows:
4
Sum of two variables in an Excel spreadsheet
z x+y
x= 5
y= 3
z= 8
5
This same sum can be done in the environment of
Visual Basic (VB)
6
You can define a function called "Sum", which receives
the value of two inputs "x" and "y" and returns the value
of the sum of them
7
How to build the function "Sum"
8
- Enter in Excel and in the main menu
click in the Developer tab.
9
If this tab is not available, see Note 1 "Activate tab" at
the end of the document.
10
Click on "view code"
11
The "Visual Basic" ambient is open
12
Function code
13
Function code
The codes are written in the VB "Modules"
14
Function code
The codes are written in the VB "Modules"
To open a module
15
Function code
The codes are written in the VB "Modules"
To open a module
Click right button on the left side window
16
17
Function code
The codes are writen in the VB "Modules"
To open a module
Click right button on the left side window
It opens a window
18
Select “Insert”
19
Click Module
20
The right window displays a flashing line
21
Sum Function Code
22
Sum Function Code
In the right window type the function name followed by
the dependent variables in parentheses, separated by a
comma.
23
Sum Function Code
In the right window type the function name followed by
the dependent variables in parentheses, separated by a
comma.
Function Suma(x,y)
24
Sum Function Code
In the right window type the function name followed by
the dependent variables in parentheses, separated by a
comma.
Function Suma(x,y)
When you press "Enter", VB automatically puts
the final line of the function.
25
Sum Function Code
In the right window type the function name followed by
the dependent variables in parentheses, separated by a
comma.
Function Suma(x,y)
End Function
26
The new code must be writen between these two commands.
27
The new code must be writen between these two commands.
In this case, the code consists of a single line
28
The new code must be writen between these two commands.
In this case, the code consists of a single line
Suma = x + y
29
The complete function looks like
30
Application of the Sum function in the Excel
spreadsheet
Type the values of x and y,
for example, in the cells
C5 and C6.
Type =SUM(C5,C&) in a
cell and press enter.
31
Application of the Sum function in the Excel
spreadsheet
The result value
appears in the cell
32
End of Part 1. Introduction
33
Activating the "Programmer" tab
34
Activating the “Developer" tab
Note 1
To activate the “Developer” tab
1. Click Options.
2. Click Customize Ribbon.
3. Choose commands from: All Tabs.
4. Select the Developer check box.
5. Click on Add
6. Activate, by clicking on Developer
7. OK
35