►
From YouTube: Office Scripts: Add Row at End of Worksheet
Description
Checkout the description here: https://github.com/sumurthy/officescripts-projects/blob/main/Range%20Basics/README.MD
Content
0:00 Introduction
0:55 Start scripting
6:40 Move logic to a function
A
Hello
in
this
video
I'm
going
to
show
you
how
to
add
a
row
at
the
end
of
a
worksheet
using
office
scripts.
So
this
is
one
of
the
most
common
question
I
get,
which
is,
how
do
I
add
a
row
at
the
end
of
a
worksheet
using
an
api?
Unfortunately,
there
isn't
a
single
api
to
be
able
to
do
that,
but
it
is
very
easy
to
use
the
existing
apis
to
write
a
simple
function.
That
does
that
for
you.
A
So,
for
instance,
I
have
a
worksheet
here
named
cheat3
and
it
has
a
table
and
some
rows
of
data
in
here
already
it
doesn't
need
to
be
in
a
table.
It
could
just
be
also
on
a
just
plain,
simple,
worksheet
in
a
regular
range,
so
the
goal
is
to
add
a
row,
a
single
row
at
the
end.
So,
as
you
can
see,
it
already
has
some
data
and
you
want
this
to
work
dynamically,
regardless
of
how
much
data
there
is.
A
A
A
All
right,
so
this
is
the
data
I
wish
to
add.
At
the
end.
Now
the
the
tricky
part
is
to
be
able
to
compute
the
address
so,
for
instance,
the
address
that
I'm
highlighting
here.
That
is
the
the
place
where
this
data
needs
to
go.
A
One
would
be
to
find
out
how
much
data
that
is
already
in
this
sheet
and
then
figure
out
kind
of
the
next
empty
row
and
and
then
get
the
first
cell,
where
you
want
to
start
the
the
range
update
and
compute
how
much
data
there
is
and
then
simply
update
that
that
range.
So
to
do
that,
there's
one
api
very
useful
api
called
use
range
on
a
sheet.
A
All
right
so
now
now
that
I
have
the
use
range,
I
can
then
get
the
last
row
and
then
just
compute.
The
next
row
address.
A
So
to
do
that
I'll,
say:
const
start
cell
and
off
of
the
used
range
I'll
get
the
last
row.
A
And
then
get
get
the
first
cell
so
I'll
do
zero
zero,
which
means
the
zero
row
zero
column
of
that
row,
which
in
that
case
I'll
get.
You
know
this
particular
cell,
where
there
is
data
so,
but
I
want
the
next
row
cell
so
I'll
get
get
offset
from
there
so
get
offset
range.
You
can
say,
give
me
one
row
down
and
the
same
column,
so
that
is
the
starting
cell,
so
I'll
also
display
its
address
just
so.
A
You
can
see
that
so
now
that
I
have
that
I'm
going
to
compute
how
much
x,
how
much
do
I
need
to
extend
this
row
by
so
because
I'm
only
adding
one
row,
I
just
need
to
extend
the
column,
so
I'll,
say,
target
range
and
off
the
starting
cell
I'll
do
get
resize
range,
which
means
how
much
do
I
need
to
extend
this
by
so
delta
rose?
I
don't
want
any
more
rows,
so
so
that's
zero.
So
how
many
more
columns
do
I
need
to
extend
by
remember?
A
I
already
have
one
row
and
one
column
here,
so
I'm
going
to
just
simply
get
the
data
array,
which
is
a
one-dimensional
array
value
and
it
has
a
property
called
length
which
gives
the
number
of
columns
since
it's
just
the
delta.
So
I'm
gonna
subtract
by
one,
because
I
already
have
the
first
row
first
column
accounted
for
here
and
now
that
I
have
the
target
range.
A
Set
its
values
now
set
values
takes
a
two
dimensional
array
object
because
you
can
use
the
same
api
to
update,
not
just
one
row
but
many
rows
for
now.
I
know
I'm
just
using
one
row,
so
I
can
just
directly
put
that
in
the
first
row
so
yeah
I
think
that's
about
it.
So
if
I
run
this,
I
should
see
this
row
that
I've
hard
coded
in
this
code
for
testing
to
be
added
at
the
end
of
this
this
worksheet.
A
So,
let's
see,
if
I
run
this,
so
you
can
see
that
it
added
the
data
and
you'll
also
see
it
displayed
the
address
so
which
is
a1
through
e76.
That
was
the
used
range
and
then-
and
this
was
a
starting
cell
and
then
it
computed
the
address
and
updated.
I
can
run
it
many
times.
It'll
just
simply
keep
updating
the
the
last
row.
If
you
want
to
reuse
this
in
other
parts
of
the
script,
you
can
extract
the
logic
out
to
another
function.
Let's
just
call
it
add
row
and
it
accepts
two.
A
Arguments
the
first
one
is
the
the
worksheet
itself
where
the
data
needs.
The
row
needs
to
be
added
and
then
it'll
take
the
data
and
the
data.
What
I'm
doing
here
is
defining
the
types
which
is
required
so
that
the
function
knows
what
it's
getting
and
it
can
give
you
auto
completion
as
you're
coding
along
so
and
then
for
the
data
it
needs.
A
The
I
need
to
define
the
type
so
and
the
type
can
be
like
each
cell
can
be
either
a
string
or
a
number
or
a
boolean,
and
it
is
a
it
is
an
array.
So
I'm
just
defining
a
argument
called
data
that
expects
an
array
of
either
string,
number
or
boolean.
A
Add
row
pass
in
the
sheet
and
then
the
data
so
that'll
do
the
that'll
do
the
job.
So
if
I
run
this
now,
let
me
just
reorient
it
and
run
it
okay.
So
it's
doing
the
same
work
but
all
contained
within
a
function
so
that
it's
easy
to
reuse
it
if
you
want
to
call
the
same
function
from
some
other
location
in
the
script.
A
So
that's
about
it.
So
if
you
like
this
video,
please
subscribe
like
if
you
have
questions
or
have
another
scenario
in
mind
that
you
wish
to
see
videos
for
instructions,
for
please
leave
a
comment
on
the
source
code
and
then
the
description
for
this
particular
sample
check
out
the
link.
There
is
a
link
in
the
description
that
will
take
you
to
the
source
code.
If
you
wish
to
reuse
it
all
right,
thanks
for
watching.