Page 409 - Computer Software Application TP - Volume 1
P. 409
COMPUTER SOFTWARE APPLICATION - CITS
Step 4: Write the Code:
Explanation:
1 Sub R1C1Style(): This line defines the beginning of a subroutine named R1C1Style. Sub indicates the start of
a subroutine, followed by the name of the subroutine (R1C1Style), and parentheses to denote that it doesn’t
take any arguments.
2 Selection.FormulaR1C1 = “=rc[-2]*rc[-1]”: This line sets the formula of the selected cell or range using R1C1
reference style. Here’s the breakdown:
• Selection: Refers to the currently selected cell or range in Excel.
• .FormulaR1C1: Indicates that the formula will be assigned using R1C1 reference style.
• =: Assignment operator used to assign the following formula to the selected cell(s).
• “=rc[-2]*rc[-1]”: The formula being assigned. In R1C1 notation:
• rc[-2]: Refers to the cell in the same row (relative reference) and two columns to the left.
• *: Represents the multiplication operator.
• rc[-1]: Refers to the cell in the same row (relative reference) and one column to the left.
3 End Sub: Marks the end of the subroutine R1C1Style. This line tells VBA that the subroutine has finished and
returns control to the main program.
In summary, this subroutine sets the formula of the selected cell(s) to multiply the value in the cell two columns to
the left by the value in the cell one column to the left, using R1C1 reference style.
Step 5: Close VBA Editor:
• Close the VBA editor by clicking the close button or pressing Alt + Q.
Step 6: Run the Macro:
• Press Alt + F8 to open the “Macro” dialog.
• Choose the macro named “ ‘r1c1.xlsm’!Module2.R1C1Style” from the list.
394
CITS : IT & ITES - Computer Software Application - Exercise 67