Members-only tutorial

Watch the video and get the practice sheet with membership.

See membership options

Spreadsheet Automation 101: Variables

About this Tutorial

Dive deeper into the world of variables. Learn what variables do. Learn how to assign information to variables.

Video Transcript

<div>0:00 In last video I showed you functions Learn about functions and how they simplify tasks in spreadsheets. Opens in new tab . And in this video I'm gonna go more into more details about variables. So again, we'll go over to our extensions app script Discover how Apps Script enhances your spreadsheet capabilities. Opens in new tab and we wrote this entire new function Understand the core concept of functions in spreadsheet automation. Opens in new tab here.<br>0:15 And let me just delete this and start over. So in our function Understand the core concept of functions in spreadsheet automation. Opens in new tab that we write, we can write a variable and a variable allows us to basically simplify a lot of things.<br>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.<br>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.<br>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.<br>0:56 But we have a function Understand the core concept of functions in spreadsheet automation. Opens in new tab and we can have multiple variables. We can have, like, we can use the word one to equal one.<br>1:05 When we assign a variable, we use the equal sign.

The equal sign here does not mean EQ is equal two.<br>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.<br>1:22 We can do variable two is or equal sign two. And then we can do some math in these functions Learn about functions and how they simplify tasks in spreadsheets. Opens in new tab , right?<br>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.<br>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.<br>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 Explore the basics of spreadsheets and their functionalities. Opens in new tab .<br>2:09 So we gotta save. Now all we have to do is call my function Understand the core concept of functions in spreadsheet automation. Opens in new tab . And how we do that is we do equals my function Understand the core concept of functions in spreadsheet automation. Opens in new tab with the parenthesis and we get the number Get insights into how numbers are handled in spreadsheet formulas. Opens in new tab seven.<br>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.<br>2:32 It is now three. So dysfunction has given us our A name to do and we can get something in return.<br>2:41 We can also use variables inside of the name of the function Understand the core concept of functions in spreadsheet automation. Opens in new tab in these parentheses. That's what this parenthesis allows us to do with this.<br>2:48 This is sometimes called parameters Find out how parameters work in functions for dynamic calculations. Opens in new tab .

I might be using that word a lot parameters Find out how parameters work in functions for dynamic calculations. Opens in new tab when I refer to functional functions Learn about functions and how they simplify tasks in spreadsheets. Opens in new tab variables here in this particular case.<br>2:58 But These, these here that say var, those are variables. So these parameters Find out how parameters work in functions for dynamic calculations. Opens in new tab could be one and comma two. So we can add more than one parameter Learn about the role of parameters in function definitions. Opens in new tab here.<br>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.<br>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 Understand the core concept of functions in spreadsheet automation. Opens in new tab on the sheet side plus the other one.<br>3:30 So let's see what that is. So let's save this and we might get an error Understand common errors in Google Sheets and how to fix them. Opens in new tab , but we'll, before we get an error Understand common errors in Google Sheets and how to fix them. Opens in new tab , we'll add two numbers.<br>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.<br>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 Understand the core concept of functions in spreadsheet automation. Opens in new tab CPM where Dive into using the WHERE clause in queries for data filtering. Opens in new tab we have a cost and views.<br>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?<br>4:23 And we can return the cpm, we can hit save. And now we have to change this function Understand the core concept of functions in spreadsheet automation. Opens in new tab , CPM 55, 45 and a bunch of numbers.<br>4:37 And we can see we get some CPM here, right? This is very, very powerful because now we can create functions Learn about functions and how they simplify tasks in spreadsheets. Opens in new tab that have completely custom parameters Find out how parameters work in functions for dynamic calculations. Opens in new tab , completely custom variables.<br>4:51 We can return information, we can do math inside of these functions Learn about functions and how they simplify tasks in spreadsheets. Opens in new tab .

And now we're gonna be going into many, many more interesting things that we can do inside these functions Learn about functions and how they simplify tasks in spreadsheets. Opens in new tab .</div>

Courses

Spreadsheet Automation 101: Introduction to Pre-course Videos

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

How To Change Date Format Automatically

Tips to Navigating Thousands of Lines of Code In Apps Script

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

Breaking Through Errors In Apps Script

VAR vs CONST vs CONSTANT in Apps Script