GoogleAppsScript PDF
GoogleAppsScript PDF
P P E N D I X
INTRODUCTION
Google
Apps
Script
(or
Apps
Script
in
short)
is
the
accompanying
programming
interface
that
is
tightly
coupled
with
Google
Sheets
to
perform
more
advanced
automation.
It
has
as
its
backbone
the
JavaScript
(JS)
programming
language
and
added
elements
to
permit
it
to
interact
with
the
component
objects
of
Google
Sheets
(and
also
other
applications
in
the
Google
Productivity
Apps
suite).
In
a
Google
spreadsheet,
select
Tools/Script
editor
to
access
the
Script
Editor.
With
this,
codes
written
thereafter
will
be
stored
with
this
file.
Once
invoked,
a
dialog
as
shown
in
Figure
B-1a
will
be
displayed.
Click
Blank
Project.
The
Script
Editor
and
Integrated
Development
Environment
(IDE)
window
as
shown
in
Figure
B-1b
will
appear.
Click
on
Untitled
Project
to
rename
the
project.
Then
using
code
stub
myFunction,
renaming
it
if
you
like,
to
write
your
own
function.
In
Apps
Script,
the
reserved
word
function
is
singly
used
to
denote
both
function
and
subroutine,
as
opposed
to
separate
reserved
words
such
as
Function
and
Sub
respectively
in
Excel
VBA.
Further
explanations
are
in
Note
17.
Figure
B-1a
Google
Apps
Script
Startup
FURTHER
REFERENCES
o http://dl.dropboxusercontent.com/u/19228704/SpreadsheetModeling.htm#Googl
eAppsScript
Maguire,
2014.
Google
Spreadsheet
Programming:
Use
JavaScript
to
Build
Spreadsheet
Applications
in
the
Cloud,
Leanpub.
NOTES
Note
16:
MACRO
RECORDING
Let
us
now
follow
how
a
simple
macro
recording
is
done
in
Excel
and
then
attempt
to
read
and
understand
the
codes
created.
You
may
skip
this
note
and
come
back
to
it
later
after
reviewing
Note
17.
Example:
Record
a
macro
to
do
automatic
copying
and
pasting
of
values
1.
In
a
new
workbook,
select
Developer/Record
Macro
(or
Tools/Macro/Record
new
macro
in
Excel
2003).
2.
A
Record
Macro
dialog
box
as
shown
in
Figure
B-2
will
appear.
Enter
the
macro
name
of
your
choice,
assign
a
shortcut
key
(if
needed),
select
where
to
store
the
macro
(the
default
location
being
the
current
workbook),
and
finally
enter
a
short
description.
For
this
example,
we
will
accept
all
the
given
defaults.
Figure
B-2
Macro
Recording
Dialog
3.
Click
OK.
Once
it
is
clicked,
whatever
actions
you
do
with
your
mouse
or
keyboard,
such
as
selecting
a
cell
or
scrolling
up
and
down
the
worksheet,
will
be
recorded
as
codes.
[In
Excel
2003,
a
small
Stop
Recording
dialog
(or
toolbar)
will
appear
when
macro
recording
starts.
It
has
two
buttons,
the
Stop
Recording
button
on
the
left
and
the
Relative
Reference
button
on
the
right.
You
should
never
click
the
dialog-close
(X)
button
in
the
upper
right-hand
corner
as
this
will
make
the
dialog
box
disappear.
If
you
ever
make
that
mistake,
you
can
recover
the
dialog
box
by
selecting
from
the
main
menu
View/Toolbars,
and
then
select
Stop
Recording.]
4.
Deactivate
the
Use
Relative
References
button
if
it
is
activated,
select
cells
B2:B5.
Right-click
and
select
Copy
in
the
pop-up
side
menu
(as
shown
in
Figure
B-3).
5.
Select
cell
C2
(by
either
clicking
with
the
mouse
or
keying
the
right-arrow
on
the
keyboard),
right-click,
and
then
select
Paste.
6.
Click
the
Stop
Recording
button
to
end
the
process.
Once
recorded,
the
macro
can
be
used
over
and
over
again.
To
run
the
macro,
select
Developer/Macros
(or
Tools/Macro/Macros
in
Excel
2003)
or
key
Alt
+
F8
and
select
the
macro
to
run.
Next,
let
us
review
and
understand
the
codes
you
have
recorded.
1.
Key
Alt
+
F11
to
launch
the
VB
Editor
(VBE)
interface.
2.
Select
Module1
and
Macro1
to
show
the
codes
in
the
Code
Window,
as
shown
in
Figure
B-4.
3.
The
codes
begin
with
Sub Macro1(
)
and
end
with
End Sub.
These
mark
the
beginning
and
the
end
of
the
subroutine.
4.
Within
the
subroutine,
a.
Line
1
=
Cell
range
B2:B5
is
selected.
b.
Line
2
=
The
selection
is
copied.
c.
Line
3
=
Cell
C2
is
selected.
d.
Line
4
=
The
copied
selection
is
pasted
with
its
upper-left
corner
in
the
selected
cell
in
the
active
sheet.
Figure
B-3
Step
4
of
Macro
Recording
Figure
B-4
Codes
for
Macro1
Notice
how
easy
it
is
to
understand
the
codes
generated.
One
way
to
speed
up
your
learning
of
the
VBA
code
and
macro
recording
is
to
have
the
Excel
and
VBE
windows
opened
side
by
side
when
you
next
record
your
macro.
See
how
each
line
of
code
is
recorded
with
each
action
you
do
in
the
Excel
window.
As
an
additional
check,
you
can
reverse
the
process
and
step
through
the
code,
making
it
run
one
line
at
a
time
to
watch
its
action
played
out
on
the
worksheet.
To
do
this,
put
your
cursor
in
the
subroutine
code
and
select
from
the
VB
Editor
main
menu
Debug/Step
Into
(or
key
F8).
Keep
keying
F8
to
see
how
the
highlight
moves
from
one
line
of
the
code
to
another
as
the
code
is
run
one
step
at
a
time.
Absolute
and
Relative
Referencing
We
have
covered
absolute
and
relative
cell
referencing
in
Note
3
of
Appendix
A.
When
you
copy
and
paste
a
spreadsheet
formula
from
one
cell
to
another,
it
automatically
adjusts
the
cell
references
in
the
formula
unless
they
have
been
made
Absolute
using
the
$
sign.
There
is
a
similar
concept
in
macro
recording.
You
should
try
to
keep
the
Use
Relative
References
button
deactivated
as
soon
as
it
is
not
required
so
that
cell
referencing
will
be
absolute
by
default.
What
this
means
is
that
every
selection
of
a
cell
would
refer
to
that
cell
and
is
not
interpreted
as
some
relative
movement
from
the
last
active
cell.
You
can
record
the
same
macro
as
in
the
earlier
example,
but
this
time,
select
cell
B2
before
recording
the
macro
and
activate
the
Use
Relative
References
button
in
the
beginning
of
the
macro
(and
thereafter
remember
to
set
it
back).
Study
the
difference
between
the
two
approaches.
1.
Select
Developer/Record
Macro
(or
Tools/Macro/Record
new
macro
in
Excel
2003).
2.
In
the
dialog
box
as
shown
in
Figure
B-2,
enter
Macro2
as
the
macro
name,
and
leave
the
other
inputs
as
default
values.
3.
Click
OK.
4.
Activate
the
Use
Relative
References
button.
Once
activated,
you
will
see
an
orange
shaded
border
surrounding
the
button.
5.
Select
cells
B2:B5,
right-click,
and
select
Copy.
6.
Select
cell
B2
and
key
the
right-arrow
on
the
keyboard.
Right-click,
select
Paste
from
the
side
menu.
7.
Deactivate
Use
Relative
References.
8.
Click
Stop
Recording
to
end
the
process.
Let
us
read
the
codes
for
Macro2
as
shown
in
Figure
B-5.
Line
1
=
A
column
of
four
cells
from
the
current
active
cell
is
selected.
Since
cell
B2
was
selected
before
the
macro
was
recorded,
this
means
cells
B2:B5
is
selected.
A1:A4
reference
here
is
with
respect
to
the
active
cell
as
the
origin
A1
cell.
Line
2
=
The
selection
is
copied.
Line
3
=
A
relative
offset
of
zero
row
down
and
one
column
to
the
right
from
the
active
cell
(cell
B2
in
our
case)
is
selected.
A1
here
denotes
only
one
cell
is
selected.
Movements
up
and
to
the
left
are
recorded
as
negative
argument
values
in
Offset.
7
Relative
referencing
provides
greater
flexibility
as
new
active
cells
(to
be
selected
before
the
macro
is
run)
can
be
any
cell
in
any
worksheet.
For
this
demonstrated
macro,
it
means
that
we
can
copy
and
paste
any
column
of
four
cells
to
its
immediate
right.
Figure
B-5
Codes
for
Macro2
Quick
Tip
1
o After
each
copy
and
paste
sequence
of
operations,
Excel
leaves
behind
highlighted
cell
range
selections
and
dotted
box
outlines
in
the
worksheet.
It
is
a
good
housekeeping
practice
to
end
your
macro
with
the
cursor
place
in
the
appropriate
cell
and
clear
away
all
such
unwarranted
distractions.
In
the
spreadsheet,
just
point
your
mouse
to
the
end
cell
location
and
key
Esc.
o The
corresponding
macro
statements
at
the
end
of
your
Sub
are
as
follows:
Range(A1).Select
Application.CutCopyMode = False
Apps
Script
is
based
on
the
object-oriented
Java
and
JavaScript
languages.
Thus
it
is
useful
to
first
understand
the
hierarchy
of
objects
to
better
use
the
properties,
methods,
and
events
of
the
objects.
The
hierarchy
of
Google
Sheets
objects
is
given
as
follows:
SpreadsheetApp
Spreadsheet
Function
Add-on
Spreadsheet
Chart
Sheet
Range
Cell
Properties
Each
object
has
its
own
set
of
Properties
that
describes
it.
Some
of
the
properties
of
the
Range
object
include
row
height,
column
width,
and
font.
You
can
set
the
value
of
cell
E7
to
10
and
change
its
font
color
to
red
using
the
code
below:
var sheet = SpreadsheetApp.getActiveSheet();
sheet.getRange(C7).setValue(10);
sheet.getRange(C7).setFontColor(red);
In
general,
any
property
can
be
set
using
the
syntax
below:
Object.setProperty()
Methods
Each
object
also
has
its
own
associated
set
of
Methods,
which
are
actions
that
can
be
performed
on
it.
For
example,
one
of
the
methods
for
the
Range
object
is
ClearContents.
You
can
clear
the
contents
of
a
selected
range
C7:D9
using
the
code
below:
var sheet = SpreadsheetApp.getActiveSheet();
sheet.getRange(C7:D9).clearContent();
In
general,
any
method
can
be
activated
using
the
syntax
below:
Object.Method
Quick
Tip
1
Apps
Script
programming
is
quite
user-friendly.
It
provides
coding
help
as
you
type
in
the
code.
After
you
have
entered
the
dot
(.)
following
the
object
name,
a
drop-
down
list
will
appear
as
shown
in
Figure
B-6,
listing
all
the
available
properties
and
methods
associated
with
this
object.
Do
remember
that
JavaScript
and
thus
Apps
Script
are
case-sensitive.
That
is,
you
have
to
write
given
keywords
as
provided;
do
not
change
their
letters
in
lower
cases
to
upper
cases,
and
vice-versa.
9
If
you
have
been
working
with
Excel
VBA,
here
is
a
general
difference
between
that
and
Apps
Script
that
you
should
note.
When
an
Excel
object
(e.g.,
cell
range),
is
referenced
in
VBA,
this
object,
unless
explicitly
coded,
is
assumed
to
be
in
the
currently
active
Excel
container
(e.g.,
the
active
workbook
and
active
worksheet).
In
Apps
Script,
each
reference
to
a
Google
Sheets
object
must
be
fully
qualified;
you
have
to
specify
the
spreadsheet
document
and
sheets
explicitly
as
shown
below:
numCars =
SpreadsheetApp.getActiveSheet.getRange(C7).getValue();
If
you
want
to
get
another
spreadsheet
document
and
sheet,
this
can
be
as
show
below:
//Open your spreadsheet document ----SpreadsheetApp.setActiveSpreadSheet();
SpreadsheetApp.getSheetByName(Sheet1).Activate;
var sheet = SpreadsheetApp.getActiveSheet();
numCars = sheer.getRange(C7).getValue();
//Close your spreadsheet document ----
You
may
need
to
remember
first
the
active
spreadsheet
document,
sheet,
and
cell,
and
return
there
after
you
are
done
so
that
it
would
not
affect
other
macros.
This
is
done
as
follows:
var oActiveSpreadsheet =
SpreadsheetApp.getActive();
var oActiveSheet =SpreadsheetApp.getActiveSheet();
var oActiveCell = SpreadsheetApp.getActiveCell();
10
Quick
Tip
2
The
//
sign
(and
also
htmls
<!--)
is
the
shorthand
for
comments.
All
statements
that
appear
after
the
sign
to
the
end
of
the
line
will
be
regarded
as
mere
comments
and
not
code.
You
can
sprinkle
your
macro
with
comments
to
make
it
easier
to
understand
and
read.
For
comments
that
span
multiple
lines
use
/*
to
start
and
*/
to
end.
The
other
best
practice
is
to
indent
lines
when
they
are
part
of
another
programming
structure.
In
this
case,
you
can
see
that
all
statements
between
a
function
start
and
end
are
indented
to
show
that
they
are
part
of
the
function.
You
can
observe
how
they
are
used
in
other
examples
later
in
the
chapter.
Similarly,
when
you
record
macros
in
Excel,
values
can
only
be
transferred
from
one
set
of
cells
to
another
using
Copy
and
PasteSpecial
as
shown
in
Note
16.
When
you
edit
the
macro,
rewrite
it
in
App
Scripts
to
work
directly
with
objects
as
shown
below.
var sheet = SpreadsheetApp.getActiveSheet();
var range1 = sheet.getRange(B2:B5);
var range2 = sheet.getRange(C2:C5);
range2.setValues(range1.getValues());
The
above
transfers
values
between
two
cell
ranges.
When
there
are
only
single
cells
involved,
the
code
is
even
simpler:
sheet.getRange(C2).setValue(
sheet.getRange(B2).getValue());
Other
than
transferring
data
values
between
cells,
you
can
set
formulas
in
any
cell
in
the
spreadsheet
as
demonstrated
below:
sheet.getRange(A12).setFormula (=SUM(A2:A11));
11
When
the
choice
of
cell
uses
depends
on
other
values,
use
the
Offset
method
as
follows:
var r = 3; var c = 1;
sheet.getRange(C3).setValue(
sheet.getRange(A1).offset(r,c).getValue());
sheet.getRange(A1).Offset(3,1)
refers
to
cell
B4.
The
above
thus
set
the
value
in
cell
B4
to
cell
C3.
Subroutine
and
Function
Procedures
A
Sub
procedure
(or
subroutine)
is
a
set
of
codes
which
when
executed
performs
a
series
of
spreadsheet
actions.
Each
recorded
Excel
macro
is
a
Sub.
It
however
can
be
constructed
as
well.
For
example,
a
simple
subroutine
written
in
VBA
to
prompt
a
greeting
is:
Sub SayHi( )
MsgBox(Hi!)
End Sub
The
equivalent
in
Apps
Script
is
function sayHi( ){
Browser.msgBox(Hi!);
}
Note
that
Apps
Script
uses
the
keyword
function
instead
of
Sub.
This
is
not
a
mistake,
but
the
notation
chosen
by
Google
for
both
subroutines
and
functions.
As
a
JavaScript-based
language,
it
uses
the
{
and
}
curly
brackets
to
denote
start
and
end
respectively
of
the
function
code,
as
well
as
of
code
segments.
Also
do
remember
to
end
each
line
of
code
with
a
semi-colon,
a
mistake
common
among
beginners.
As
in
Excel
VBA,
each
Apps
Script
can
be
assigned
to
a
drawing
shape
in
the
Google
Sheets
and
clicking
on
each
shape
as
a
button
will
run
the
assigned
macro.
A
function
procedure
is
also
a
set
of
codes.
However,
its
primary
purpose
is
to
return
a
result
computed
with
the
inputs
offered
to
it.
You
may
have
used
some
of
the
given
spreadsheet
functions
like
AVERAGE
and
SUM,
and
soon
you
will
be
able
to
create
more
useful
functions
of
your
own.
Let
us
begin
by
writing
a
simple
function
to
compute
the
cube
root
of
a
number.
In
order
for
the
function
to
return
the
computed
value
when
the
function
is
used,
the
result
variable
must
bear
the
functions
name,
which
in
this
case
is
CubeRoot.
In
an
empty
space
in
a
workspace,
type
in
the
following:
function cubeRoot(number) {
return number^(1/3);
}
12
}
Declaring
Arrays
An
array,
more
commonly
known
as
a
matrix,
is
a
group
of
variables
sharing
a
common
name.
Arrays
can
be
1-dimensional
or
multi-dimensional.
An
example
of
a
1-dimensional
array
declared
to
store
the
identification
number
of
compact
disks
is:
var cd_id = new Array(); //or
var cd_id = [];
An
example
of
a
2-dimensional
array
declared
to
store
the
identification
number
of
compact
disks
is:
13
switch (expression) {
case condition 1: statement set 1
break;
case condition 2: statement set 2
break;
case condition 3: statement set 3
break;
default: statement set n+1
}
An
example
is
given
below:
function switchCaseDemo() {
var rating = InputBox(Enter rating 1, 2 or 3: );
switch rating {
case 1:
Browser.msgBox (You have entered 1.);
etc
break;
case 2:
Browser.msgBox (You have entered 2.);
etc
break;
case 3:
Browser.msgBox (You have entered 3.);
etc
break;
default:
Broswer.msgBox(You have entered others.;
break;
}
When
you
need
the
program
to
loop
through
a
set
of
codes
for
some
number
of
times,
the
For-Next
statement
will
be
very
handy.
The
looping
is
controlled
by
a
counter
that
will
go
from
a
start
number
to
an
end
number,
increasing
by
a
stepSize
after
each
execution
of
the
loop.
When
not
declared,
a
default
step
size
is
1.
for (counter=start; test condition; iteration) {
statements
}
See
the
example
given
below:
function forLoopDemo() {
for (var j=1; j<10; j++) {
MsgBox(Hi);
}
}
15
Apps
Script,
like
Java,
JavaScript
and
others
using
the
C
language
syntax,
denote
increment
by
1
with
++
and
decrement
by
1
with
.
The
program
above
displays
the
message
Hi
for
10
times,
using
j
as
the
counter.
A
Do-While
statement
is
useful
when
you
need
the
program
to
loop
through
a
set
of
codes
until
a
test
condition
returns
a
FALSE.
Do-While
can
be
used
in
two
slightly
different
methods.
Method
1:
This
method
tests
the
condition
first,
and
executes
the
statement
when
the
condition
is
tested
TRUE.
The
program
ends
immediately
when
the
test
condition
results
in
a
FALSE.
while (testCondition)
{
statements
}
Method
2:
This
alternative
method
executes
the
statement
first,
and
then
tests
the
condition.
Only
when
the
condition
is
tested
TRUE
will
the
next
iteration
be
executed.
Similarly,
the
program
ends
when
the
test
condition
returns
a
FALSE.
The
main
difference
is
that
the
codes
in
the
loop
in
method
2
will
be
executed
at
least
once,
whereas
this
may
be
by-passed
completely
in
method
1.
do {
statements
} while (testCondition);
The
corresponding
examples
are
as
follows:
function doWhileDemoMethod1() {
while (j < 10) {
Browser.msgBox(Hi);
j += 1;
}
}
Method
2:
function doWhileDemoMethod2() {
do {
MsgBox (Hi);
j += 1;
} while (j < 10);
}
Note
19:
SOLVER
AND
ADD-INS
Add-on
(or
Add-in
in
Excel)
functions
and
operations
are
contained
in
workbooks,
each
typically
denoted
in
Excel
by
the
.xla
or
.xlam
extension.
For
example,
Solver
operations
16
are
in
Solver.xla
and
Solver.xlam
workbooks.
An
add-in
is
only
available
after
it
has
been
activated.
In
Excel
2003,
this
is
done
by
selecting
Tools/Add-ins
and
ticking
on
the
relevant
items.
In
Excel
2007,
select
Office/Excel
Options/Add-ins/Excel
Add-ins/Go.
Activating
an
add-on
only
allows
it
to
run
in
the
spreadsheet.
Macros
recorded
with
add-in
operations
may
not
work.
For
example,
Solver
operations
will
not
run
in
the
macros,
unless
in
addition
the
Solver.xla
file
is
referenced
in
the
Visual
Basic
Editor
(VBE)
for
the
project.
This
is
done
by
selecting
in
VBE
Tools/Reference
and
then
ticking
the
check
box
for
Solver.
You
may
have
to
browse
for
it
if
it
is
not
there
in
the
selection
list.
The
file
is
usually
found
in
c:\Program
Files\Microsoft
Office\Office
12\Library\Solver.
The
file
to
link
to
is
Solver.xlam
and
not
Solver.dll.
For
Excel
2003,
the
folder
is
Office
11
instead
and
the
file
is
Solver.xla.
Google
Sheets
does
not
support
macro
recording
and
it
is
still
not
possible
to
write
Apps
Script
codes
to
customize
Solver.
Thus,
the
above
comments
are
only
for
cross-
reference
to
Excels
capabilities,
in
case
there
are
new
developments
to
look
out
for.
Note
20:
AUTOMATIC
PROCEDURES
AND
EVENTS
Trigger
procedures
are
programs
that
are
activated
by
interactive
actions
or
events.
Every
object
has
their
associated
events,
such
as
onOpen
for
spreadsheet
and
onEdit
for
sheets.
For
example,
to
automatically
execute
a
macro
whenever
a
spreadsheet
is
opened,
you
can
write
a
function
onOpen
procedure
in
the
spreadsheet.
An
example
of
the
codes
that
you
can
put
in
this
is
shown
below:
function onOpen() {
SpreadsheetApp.getActiveSpreadsheet()
.getSheetByName("Home").getRange(A1).Activate;
}
Similarly,
onEdit
detects
any
change
in
value
in
a
sheet.
The
remaining
code
that
follows
can
take
the
changed
value
and
doing
something
with
it.
function onEdit(e){
var range = e.range;
var newValue = range.getValue();
other statements to work on newValue ..
}
Note
21:
RUN-TIME
ERROR
HANDLING
Imagine
that
you
wrote
a
simple
subroutine
to
compute
the
square
root
of
a
user-input
value.
In
order
to
ensure
that
the
user
has
entered
a
positive
value,
you
need
to
test
the
input
value
before
executing
the
computation.
You
test
by
checking
if
the
value
is
positive
and
if
it
is
numeric.
Alternatively,
you
can
use
a
general
error
handling
statement
to
trap
all
possible
errors
whenever
they
occur.
17
function squareRootDemo() {
...
try {
var num = InputBox (Enter a value: );
If (num != ) {
activeCell.setValue(Sqr(num));
}
}
catch(err) {
Browser.msgBox (Make sure you enter a positive
numeric value);
}
}
This
example
allows
the
subroutine
to
proceed
straight
to
the
error
message
whenever
the
user
input
threatens
to
trigger
a
computation
error.
Note
22:
SPREADSHEET
PROGRAMMING
APPROACH
There
are
really
four
approaches
to
programming
a
spreadsheet.
The
first
is
to
use
only
spreadsheet
functions
and
features
(this
topic
is
covered
in
Appendix
A).
Since
its
inception,
spreadsheet
application
software
has
come
a
long
way.
Features
that
were
once
only
available
in
programming
languages
are
now
regularly
available
and
used
in
spreadsheets.
The
basic
ones
permit
one
variable
(as
represented
by
a
cell)
to
take
values
from
other
variables,
use
of
If-Then-Else
logical
branching,
and
multiple-stage
computations
with
relative
cell
referencing.
More
recently,
there
are
random
variables,
iterative
or
recursive
computations,
Lookups,
and
automated
computation
(i.e.,
loops
in
the
form
of
DataTable
operations,
though
not
available
yet
in
Google
Sheets).
Working
on
a
spreadsheet
workbook
is
really
programming
work,
though
many
do
not
see
it
as
such.
The
second
approach,
also
not
available
in
Google
Sheets,
is
to
record
mouse
and
keyboard
actions
as
macros,
and
run
these
macros
as
automated
steps
in
the
spreadsheet
operations.
The
steps
are
visible
to
the
user
by
default,
though
it
can
be
masked
to
speed
up
operations.
All
the
calculations
are
done
in
the
sheets
and
so
the
user
can
vividly
review
the
interactions
between
variables.
The
third
approach,
to
extend
the
abilities
of
macros,
is
by
adding
programming
codes
to
do
what
mouse
and
keyboard
actions
on
the
worksheets
cannot
achieve.
In
addition,
the
recorded
macros
can
be
tidied
up
and
made
more
efficient,
for
example,
by
removing
worksheet
selections,
cell
selections,
and
copy-paste
operations,
replacing
them
with
codes
that
work
directly
with
spreadsheet
objects.
The
fourth
and
final
approach
is
to
write
subroutines
and
functions
using
the
macro
language,
with
minimal
use
of
spreadsheet
features,
other
than
to
read
data
and
write
results.
This
is
no
different
than
normal
computer
programming,
except
now
the
worksheets
become
data
storage
and
reporting
pages.
The
computations
are
all
done
in
18
the
lines
of
codes
and
therefore
the
user
must
be
able
to
read
the
computer
language
to
understand,
debug,
and
maintain
the
codes.
We
prefer
the
third
approach
since
the
computer
program
in
spreadsheets
plus
macros
is
already
extremely
powerful.
On
top
of
that,
it
is
transparent
and
dynamic.
This
means
that
you
can
build
a
spreadsheet
model
with
nontechnical
people
and
its
results
are
immediately
responsive
to
changes
in
input
values.
Transparency,
dynamism,
and
ease
of
use
are
the
key
strengths
of
spreadsheets;
no
other
analytical
software
comes
close
to
matching
spreadsheets.
No
other
software
would
be
as
readily
accessible
to
novices
and
experts
alike
for
situational
exploration
and
problem
discovery.
And
to
beat
that,
the
work
done
in
these
first
steps
can
be
further
extended
into
user-friendly
solutions,
data
and
solution
analyses,
and
management
reports.
19