Academy ↓

# Hey there stranger!

Sign up to get access.

# Spreadsheet Automation 101: Variables

About this Tutorial

Video Transcript

0:15 And let me just delete this and start over. So in our function that we write, we can write a variable and a variable allows us to basically simplify a lot of things.

0:30 Or it also lets us repeat things a lot. So we can do variable and v r is the what we use here.

0:37 We can also use C O N S T const. You might see that if you are already copied and pasting code into your sheets and you see const cons and variable are very, very similar.

0:51 In fact, they're almost the same. There are a couple of differences, but we're not gonna go over that in this video.

0:56 But we have a function and we can have multiple variables. We can have, like, we can use the word one to equal one.

1:05 When we assign a variable, we use the equal sign. The equal sign here does not mean EQ is equal two.

1:12 What I like to do is I like to think of it as the word is, it is assigning the word one with whatever we put behind here.

1:22 We can do variable two is or equal sign two. And then we can do some math in these functions, right?

1:30 So we can create a whole new variable, variable three, that is one plus two. Now we've only been able to do this wording one plus two because we've assigned the variables one and two to one and two.

1:49 If we had perhaps done three or four here even though the word is one it is assigned the actual value of three.

2:00 And then just like we learned in the last video, we can return three. So let's actually look at that now in our spreadsheet.

2:09 So we gotta save. Now all we have to do is call my function. And how we do that is we do equals my function with the parenthesis and we get the number seven.

2:21 Why do we get that? Is because we've reassigned three and four to one and two. If we do change three to one and four to two, save that we come back.

2:32 It is now three. So dysfunction has given us our A name to do and we can get something in return.

2:41 We can also use variables inside of the name of the function in these parentheses. That's what this parenthesis allows us to do with this.

2:48 This is sometimes called parameters. I might be using that word a lot parameters when I refer to functional functions variables here in this particular case.

2:58 But These, these here that say var, those are variables. So these parameters could be one and comma two. So we can add more than one parameter here.

3:09 That can be defined by different thing. That can be different things. So we can change our variables one and two to one and two.

3:16 And actually we don't need any of these, these two lines. We can delete those two lines. Now this variable three is equal to whatever is gonna be entered into our function on the sheet side plus the other one.

3:30 So let's see what that is. So let's save this and we might get an error, but we'll, before we get an error, we'll add two numbers.

3:37 We'll do one, two, and ideally we get three. But look at this, we can also do 11 and 22. And it's adding those two numbers together.

3:50 So this is a pretty simple math that we can do. We can also do very complicated math. We can do something like the function CPM where we have a cost and views.

4:03 And we can say variable CPM is equal to, or is, sorry, not is equal to is cost divided by views view divided by 1000, right?

4:23 And we can return the cpm, we can hit save. And now we have to change this function, CPM 55, 45 and a bunch of numbers.

4:37 And we can see we get some CPM here, right? This is very, very powerful because now we can create functions that have completely custom parameters, completely custom variables.

4:51 We can return information, we can do math inside of these functions. And now we're gonna be going into many, many more interesting things that we can do inside these functions.

Courses

Spreadsheet Automation 101: Introduction to Pre-course Videos

Breaking Through Errors In Apps Script

Think Like a Programmer: Develop The Mindset of an Apps Script Coder

Spreadsheet Automation 101: Functions

Spreadsheet Automation 101: Variables

Spreadsheet Automation 101: Dot Notation

Spreadsheet Automation 101: Camel Case

Spreadsheet Automation 101: Parentheses

Spreadsheet Automation 101 Lesson 1: GetValue - Introduction to SpreadsheetApp

Spreadsheet Automation 101 Lesson 1: Spreadsheet Taxonomy

Spreadsheet Automation 101 Lesson 1: A1 Notation vs Row,Column Syntax

Spreadsheet Automation 101 Lesson 1: getActiveSpreadsheet() vs getActiveSheet()

Spreadsheet Automation 101 Lesson 1: onOpen() Trigger - Custom Menu

This Seems Like Automation

Spreadsheet Automation 101 Lesson 2: Get Values - Introduction

Spreadsheet Automation 101 Lesson 2: Arrays

Spreadsheet Automation 101 Lesson 2: For Loop

Spreadsheet Automation 101 Lesson 2: Bracket Notation

Spreadsheet Automation 101 Lesson 2: Logger.log()

Spreadsheet Automation 101 Lesson 2: If ( ){ } and Checkboxes

Spreadsheet Automation 101 Lesson 2: onEdit() Trigger

Introduction to Spreadsheet Automation 101 Lesson 3

Spreadsheet Automation 101 Lesson 3: MailApp

Spreadsheet Automation 101 Lesson 3: Email Yourself For Loop

Spreadsheet Automation 101 Lesson 3: Send Email Every Week Trigger

Spreadsheet Automation 101 Lesson 3: Email Other People For Loop

Spreadsheet Automation 101 Lesson 4: Access APIs Introduction

Spreadsheet Automation 101 Lesson 4: UrlFetchApp

Spreadsheet Automation 101 Lesson 4: OmdbAPI get ApiKey, get Data in URL

Spreadsheet Automation 101 Lesson 4: OmdbAPI get data in Apps Script

Spreadsheet Automation 101 Lesson 4: JSON (beautifier) and OmdbAPI parameters

Spreadsheet Automation 101 Lesson 4: OmdbAPI Parameter Picker

Automatically Clear Content | Refresh Reuse Recycle Templates

Automate Google Sheets With Zero Experience

Automatically Uncheck A Daily Checklist

Activate A Certain Sheet When Opening a Spreadsheet

Scoping Functions in Apps Script