Page 169 - IT_V1.0_Class10
P. 169
Step 4: Click on the OK button.
1
3
Notes
4
2 The actions recorded by macro
are recorded as instructions in a
programming language called BASIC.
The new module is created.
To Create or Edit a Macro using Function
Consider a situation where you have to apply some long or complex formula repeatedly and for which direct
inbuilt formula is not available, then we can write the formula and store it as a function and whenever needed
we can use it.
Let’s create a function named NumberFive() that displays the digit 5 on execution.
The user can type code of the Number Five function, which returns the number five. The statement Option
Explicit forces all variables to be declared before they are used. If Option Explicit is omitted, variables are
automatically defined at first use as type Variant.
Click on Tools macros Organize macros Basic/Tools Macros Edit macros
Write the codes between the Section Function and End Function
REM ***** BASIC *****
Option Explicit
Sub Main
End Sub
Function NumberFive()
NumberFive = 5
End Function
Click on Save button to save the code.
Function in a programming language refers to a block of statement that performs certain task. Few functions
are inbuilt whereas few functions are user defined. A function can contain arguments or not.
Argument refers to the data input on which the function will work and return a result.
Suppose a function is defined as areacircle (2). It denotes that this function will calculate area of circle with
radius 2.
Using Macros in Spreadsheet 167

