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
zx + y x =5 y =3 z =z =8 5 Sum of two variables in an Excel spreadsheet
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
10 If this tab is not available, see Note 1 "Activate tab" at the end of the document.
Click on "view code" 11
The "Visual Basic" ambient is open 12
Function code 13
Function code 14 The codes are written in the VB "Modules"
Function code 15 The codes are written in the VB "Modules" To open a module
Function code 16 The codes are written in the VB "Modules" To open a module Click right button on the left side window
17
Function code 18 The codes are writen in the VB "Modules" To open a module Click right button on the left side window It opens a window
19 Select “Insert”
Click Module 20
The right window displays a flashing line 21
Sum Function Code 22
Sum Function Code 23 In the right window type the function name followed by the dependent variables in parentheses, separated by a comma.
Sum Function Code 24 In the right window type the function name followed by the dependent variables in parentheses, separated by a comma. Function Suma(x,y)
Sum Function Code 25 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.
Sum Function Code 26 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
The new code must be writen between these two commands. 27
The new code must be writen between these two commands. 28 In this case, the code consists of a single line
The new code must be writen between these two commands. 29 In this case, the code consists of a single line Suma = x + y
30 The complete function looks like
31 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.
32 Application of the Sum function in the Excel spreadsheet The result value appears in the cell
End of Part 1. Introduction 33
Activating the "Programmer" tab 34
Activating the “Developer" tab 35 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