Hey there stranger!

Sign up to get access.

Write Your First Script

About this Tutorial

I walk you through everything you may encounter along the way of coding in Google Apps Script. Discover the challenges and pitfalls before you fail. If you’ve never coded before, I’m right there with you all the way.

Video Transcript

 Hi. In this video we're gonna get to scripting. I'm not going to show you everything, so if you've done scripting before, you probably have done exactly what I'm about to do, but we're gonna get you. Writing your first script very quickly. I'm gonna walk you through everything you'll encounter along the way.

Some problems, some challenges, some pitfalls. Let's get going cause this is gonna be really quick. And you're gonna, if you've never done scripting before, this is like mind blowing. This will infinitely expand your taste. What you can do, your tool set in Google Sheet. In this example, we're gonna do some basic math.

If we go into a cell and we say, A three is like 12 and we wanna multiply it by 12, we would do this, right? We would do a times 12, right? But what we could do is write a script to do that so we don't have to see this function, this multiplying. I know it's simple. This is probably much simpler than what I'm about to do, but I'm gonna get you going to the scripting.

So we're gonna go up to tools. We're gonna go to the script editor button. And this is what it looks like, what it load up. This is what it looks like when you're, when it's brand new. I haven't done a single thing yet. It's run. You'll get maybe a message here. Just dismiss that. Now your code says Untitled Project at the top says Code Gs here.

This is, you can add multiple sheets of code. And we could write multiple codes in each sheet, but right now we're just gonna write one in Code Gs. We don't have to change that name. We do have to name this. I'd just like to name it this name of the project. Your first script. Just a total personal way to do that so that I know.

It's titled that it's saving it. This takes some time. But while it's doing that, I'm gonna write my function. So every script has the same format. It says function space, then the name of the function that you're going to use in your sheet parenthesis. And this is telling us what information to get.

I'll go into that one in just a moment, and then curly brackets around the function. Okay. It gives it to you right away. You can copy and paste this. You can rename them. If you want to do multiple, we will do multiple. But let's just do one right now and let's call it multiply by 12. I know this is way more characters than literally doing asterisks 12, but let's just get it done.

I'll show you what you have to do. So first we need something to multiply by. So that's gonna be in these parentheses. Basically, if we write here, we're, what we're gonna end up doing is doing multiply by 12 and then putting in a. What was that? A four. So that A four. This is what we're gonna end up with.

And right now it's an unknown function. Soon they'll know what to do. That a four needs to go somewhere. So we can literally call it anything. We'll just call it Nu number. Okay, call it number. Now we want to take that number and we're gonna end up with a result. So where you gotta say return, let's say answer.

That's it. But we need to get an answer, right? So we need to turn this number into this answer and we have to multiply it by 12. This is how we do it. Uvar as in a variable. So what variable answer equals number, and then we do exactly what we did before, times 12. So we can do that without spaces. With spaces.

I'm gonna do command S to save. So all I'm doing is saving. We can make that a few lines so you can see that. So function multiply by 12 is taking a number, the input is number, and it's saying number times 12. Make that the answer and return it. Give that to me. Give me the answer. That's this number times 12, so let's go check it.

So we saved everything. Everything is saved. If it's not saved. If we've made an edit, it'll have this red button, no, not button. Asterisks there, and then means you have to save or you've changed something. So now let's go back here and let's go here. Let's go. 12. We'll do equals multiply. See, it doesn't show up here.

We have to remember what it is cuz it's a special one. We just did ourselves a six and it'll have a red line underneath, but the difference will be, now it says loading and now it has the answer. So this answer multiply by 12 a six is exactly this. It worked. That's how you know you did your first script.

So go ahead and do that positive video. I'm gonna do one more thing before I end this video, but you can pause this video, go do that and come back. And once you're back, let's do something a little bit more interesting, right? Instead of one thing. So what I'm gonna do, I'm gonna just copy and paste this and this.

I'm gonna get CPM of, okay, I want to do this. I'll show you in Google Sheets, in the sheets. If I have a number, like $55 and I have a view count, like 46,000 views, a CPM is cost per thousand views. It's pretty complicated, right? So we have to do equals 55, and then we have to cost per thousand views. So we have to divide it by 46,000, divided by a thousand, and then we have to do that, right?

So we get a dollar 20 cpm. So this is something that like a lot of people have to remember and it's not hard to remember, it's just that if you're creating a sheet for someone else to use, you might have to label that. But if they're doing it on their own, we might wanna give them like an equal CPM of B eight to B nine.

We might want to give that to them. Okay, so this is how we do it and I'm also gonna show you how to do two inputs. So this is pretty cool. So we want right cost, comma views. Okay. So that's our input. We have cost and views and we just separated by a comma. So in this first one, we had one. Input In the second one, we have two inputs.

Okay? We have, and now we have to take those inputs, right? We go, we still wanna get an answer. So our answer is actually going to be cost divided by thousand views. But what is thousand views? Let's create it var. Thousand views equals views divided by 1000. So now we separate each one. Separate each one, variable, a thousand views equals view, divided by a thousand.

And then we take the cost and we're divided by that. Okay? And we return the answer, we save that, and now we, all we have to do is use CPM up. Let's go back and now it works, right? So now we can take any, we can also do this in the We can u use other cells. We can also do 55, 40 6,000. It'll still give us that red line.

It says unknown function, but once you hit enter, it'll say loading. And now all we have to do is go format number and where's our currency? Currency? Boom. And now you have a really nifty little calculator inside a function that you can name whatever you want. You've just created your own, your first, your own first script.

Enjoy. There are some other videos about getting more intricate and the learning curve's gonna ramp up. We're gonna record some macros. We're gonna record, we're gonna edit those macros, and you're gonna have a ball scripting and making them trigger to happen every day. The learning curve is ramping up.

Enjoy this. Hope you enjoyed creating your first script. Bye.

Courses

Sheet Stories / Video Notes + ADDED: Email Notifications

00:00:00

ChatGPT Clone in Google Sheets Part 2

Fast FAQS

Why Different Cell References in AI Integration in Sheets?

Show Sheet Tabs Based on Edit

Add Title Case to Google Sheets

How to Power Testimonials with Google Forms and Sheets

Getting Started Coding in Apps Script

Seek Errors When Coding Apps Script

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

ChatGPT Clone in Google Sheets Part 1

Embed a Number in a Website from a Google Sheet

Create Navigation Like A Book or Presentation

Add Click Tracking To Your Google Sheets | Bitly in a Google Sheet

00:29:08

Hold a Giveaway Raffle in a Google Sheet

Embed a Headline in a Website from Google Sheets

Capture Emails from Website Form to a Google Sheet (Without Zapier)

Quickstart Tutorial OpenAI API in Google Sheets

Create a new Spreadsheet from just a Name in a Sheet.

00:05:21

Bjarne Asks: Can I show the Last Time of the Last Edit in a sheet?

00:05:43

Email Yourself a Cell from a Google Sheet, Every Day

OpenSea Data Inside Sheets

Create an Email Campaign Stats Calculator

00:35:13

Twitter App Clone in a Google Sheet

Dylan Asks: How to Automatically Delete Rows If Cell Contains Value

Highlight Row as You Move Your Cell Selection

Create a Timer with Apps Script

LinkTree in a Google Sheet

00:11:22

Password Protecting Data In a Google Sheet

Automatic Weekly Backup of Google Sheets

Create a CPM Custom Function (Create Better Calculators!)

Move Entire Row when a Cell is changed to "Yes" - The $75,000 Google Script

00:12:29

What Can You Automate in Google Sheets? Every single trigger available to Google Sheet users

Sync Two Tabs Without ImportRange()

Google Sheets Stories? No! But we'll add timestamped video notes to your google sheets.

00:00:00

Password Protecting Data In a Google Sheet Part 2 The Basics

Benoit Asks: How to Convert Case

00:07:35

Learn to Code in Google Sheets, For Programmers

Add a Checkbox to Turn on Dark Mode

00:05:10

Write Your First Script

00:08:31

Find Keywords in Any Column. Create quick search dropdown to find keywords

00:09:37

Basic CRM - Add a Powerful Script To Move Row Based on Status

How To Improve: 1,000 Business ideas: Business Idea Generator

00:11:20

Let's Make a Bookmarklet!

00:12:37

Troubleshooting Bitly in a Google Sheet Script

00:07:07

Unique Features - Design a Better Dashboard Part 2

00:04:13

How To Set Up Stripe Webhook to Google Sheets with Google Script

00:22:10

How to Edit a Macro

00:08:22

Sheet Stories / Video Notes + Clear 24 Hour Old Videos

00:35:10

Add A Timestamp to Task Lists (without Now Formula)

00:07:44

Make your Custom Functions Like Native Functions | Custom Function Autocomplete

00:17:58

Create a Changelog Between 2 Cells Custom Function | To learn Double For Loop

00:23:26

New Syntax for WhatChanged Formula in Google Script

00:07:14

How to Record Macros

00:06:20

2 Ways to Delete Lines Quickly (CAREFUL, it's a script!)

00:09:53

Deep Inside Dark Habits Google Script

00:18:54

How to Trigger Macros Daily

00:06:58

5 Ways to Create Coupon Codes | Create UUIDs

Create a Radio Button From Checkboxes Using Google Apps Script

00:15:01