Page 235 - CITS - Computer Software Application -TT
P. 235
COMPUTER SOFTWARE APPLICATION - CITS
Show a message box
To show some message to your users, use the MsgBox function. Here's an example of such a macro in its
simplest form:
Sub Show Message () MsgBox ("Hello World!") End Sub
In real-life macros, a message box is typically used for information or confirmation purposes. For instance, before
performing a action (unmerging cells in our case), you display a Yes/No message box. If the user clicks "Yes",
the selected cells are unmerged.
Sub Unmerge_Selected_Cells () Dim Answer As String Answer = MsgBox ("Are you sure you want to unmerge
these cells?” vbQuestion + vbYesNo, "Unmerge Cells") If Answer = vbYes Then Selection.Cells.UnMerge End If
End Sub
To test the code, select one or more range containing merged cells and run the macro. The following message
will appear.
Cell reference-Relative, Absolute, Row Absolute &
Column Absolute, Reference form other sheet
Relative, Absolute, and Mixed Cell References in Excel and Sheets
A cell reference in spread sheet programs such as Excel and Google Sheets identifies the location of a cell in
the worksheet. These references use Auto fill to adjust and change information as needed in your spread sheet.
By default, a cell reference is a relative reference, which means that the reference is relative to the location of
the cell. If, for example, you refer to cell A2 from cell C2, you are actually referring to a cell that is two columns to
the left (C minus A)—in the same row (2). When you copy a formula that contains a relative cell reference, that
reference in the formula will change.
As an example, if you copy the formula =B4*C4 from cell D4 to D5, the formula in D5 adjusts to the right by one
column and becomes =B5*C5. If you want to maintain the original cell reference in this example when you copy
it, you make the cell reference absolute by preceding the columns (B and C) and row (2) with a dollar sign ($).
Then, when you copy the formula =$B$4*$C$4 from D4 to D5, the formula stays exactly the same.
222
CITS : IT&ITES - Computer Software Application - Lesson 63 - 77