Transcript Slide 1

CO357 Computing for Business and
Accounting
Lecture 13: Automation and Control
(Macros and Form controls)
Roger Sutton
[email protected]
1
Automation
Within a spreadsheet automation can be performed a variety of ways:
E.g.
1. By the spreadsheet’s re-calculation on changing a cell’s contents making use of the interdependence of the cells
2. Using the If-function – values appear in cells depending on the value
of some other cell or formula
3. Using conditional formatting – can be used to suppress displays and
hence output
4. Using macros
CO357 Computing for Business and Accounting
2
Movement between Worksheets
Generally a user moves to another sheet by clicking the required sheet tag in
the left hand corner above the task bar.
However, when software has been created for other people to use such tags,
tool bars, row and columns headers, etc. are removed. (see Excel
Options|Advanced|Display options
Movement between sheets may then be achieved using hyperlinks or buttons.
By hyperlink, a label is entered, then
Hyperlink selected from Insert|Links
to reveal the adjacent dialog :
Selecting ‘Place in this document’
allows the required worksheet to be
identified.
CO357 Computing for Business and Accounting
3
Use of IF-function
The IF function can be used to detect when cells contain particular values or no
value and then perform the required action or display in response. Conditional
formatting can be used to determine how results are displayed if at all.
co357lec08
CO357 Computing for Business and Accounting
4
Macros
A macro is a set of instructions or commands that has been recorded so that
the same sequence of actions can be reproduced comparatively easily.
A macro is used to automate tasks that are:
 repetitive
 time-consuming, or
 error-prone
In Excel, macros are expressed in Visual Basic or VBA (Visual Basic for
Applications) and saved in a special macro worksheet.
To create and use macros it is necessary to ensure the Developer tag is
shown in the ribbon – this is achieved by ticking the appropriate checkbox in
Popular of Excel Options.
CO357 Computing for Business and Accounting
5
Creating the Macro
Macros may be run either from
 a special button,
 a menu choice, or using
 a short-cut key.
A macro is created by demonstrating what is required so that a record can be
made.
It is recommended that you run through the intended operation a few times to ensure
that all steps are included and then write these steps down on paper.
Record Macro from Developer |Code reveals:
Enter a name and letter for shortcut key.
Once OK is clicked all subsequent key strokes
are recorded until the Stop recording button
in the Developer |Code panel is clicked.
CO357 Computing for Business and Accounting
6
Example: creating a pie chart
1. Click Chart icon from Insert | Charts
2. Select Pie from 2-D options
3. Click Select Data from Design|Data
4. Identify chart data range: C5:C9
5. Edit Series1
6. Identify series name: B2
7. Edit the Horizontal Axis Labels, then supply labels B5:B9.
8. Click Ok twice
9. Click Chart Labels from Layout | Labels
10. Select Centre, then More Data Label Options
11. Tick Percentage and then deselect Value (in that order!)
12. Make cell A1 active and then click Stop Recording from Developer|Code
co357lec08
CO357 Computing for Business and Accounting
7
To operate macro from a button
The set up is a two-stage operation:
1. Create the button:
Select Button from
Developer|Controls|Insert|Form Controls
Drag mouse pointer to cover cells to be
occupied by the button and release. This gives
rise to the dialog:
2. Assign the macro
The dialog provides an opportunity to assign an
existing macro or record a new one
The button labelling can be changed by holding down the Ctrl key and clicking
the button. Highlight the existing label and type in that required.
CO357 Computing for Business and Accounting
8
Form Controls
1. Spinner (Scroll bar)
Often an input value may be one of a numerical series and it is intended
that the user be allowed to examine as the input value is increased or
decreased.
Spinner:
Repayment period can be
varied by 1 from 1 to 18
months
co357lec08
CO357 Computing for Business and Accounting
9
Spinner –cont’d
The Spinner control is obtained from
Developer|Insert|Forms Controls
 Drag mouse pointer over cells to be
occupied by spinner and release to obtain:
 Use right click and select Format Control to
reveal:
 Specify minimum and maximum values,
and the incremental change
 Indicate the ‘link cell’, i.e. the cell to
contain the resulting value.
co357lec08
CO357 Computing for Business and Accounting
10
Combo box
2.
The Combo box allows a value to be selected from a column of possible
values:
Combo box:
‘Amount borrowed’ is
selected from a restricted
column of values
CO357 Computing for Business and Accounting
11
Combo box – cont’d
Once the control has been introduced onto the worksheet it is formatted using
the following dialog:
 Specify the range that contains
possible values.
 Indicate where the index of the
chosen value will be stored.
 Indicate how many lines at a
time will be shown in the list.
 To retrieve the chosen value
requires the formula:
=index( $O$7:$O$26, $O$6)
CO357 Computing for Business and Accounting
12
Radio (option) button
3.
The radio button operates like a button in
that it may be assigned a macro and this is
invoked when the button is clicked.
Radio buttons may also be grouped together
using the ‘Group‘ control
such that when one button is selected, all the
others in the group are deselected.
Using Format control, a link cell is
identified to hold the count/index of the
option button selected (The count is
assigned when the button is created).
CO357 Computing for Business and Accounting
13
Check box
Like other buttons, ticking a checkbox can
initiate an assigned macro.
Further, whereas radio buttons allow one
option to be chosen from a group, several
check boxes enable a combination of choices
to be identified and acted upon.
Using Format control, a link cell is
identified to hold the Boolean value
TRUE if the box is checked otherwise
FALSE.
CO357 Computing for Business and Accounting
14