Members-only tutorial
Watch the video and get the practice sheet with membership.
About this tutorial
Annotated transcript
24 formulas linked inline Click any highlighted terms to learn more.<div> 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.<br><br>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. Getting Started Coding in Apps Script Automate Google Sheets With Zero Experience Bigger Brain Automation is not Magic
In this example, we're gonna do some basic math.<br><br>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.<br><br>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. Turn Your Apps Scripts into Native Formulas | Apps Script Custom Function Tutorial EASY Auto Count Length
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.<br><br>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. Getting Started Coding in Apps Script Advanced Coding in Google Sheets for Programmers CLUTTERED CODE
Just a total personal way to do that so that I know.<br><br>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.<br><br>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. Getting Started Coding in Apps Script VIBE CODE GOOGLE SHEETS
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.<br><br>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.<br><br>And right now it's an unknown function . Soon they'll know what to do. That a four needs to go somewhere. Getting Started Coding in Apps Script Replace Numbers with Asterisks
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.<br><br>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.<br><br>I'm gonna do command S to save. So all I'm doing is saving. Replace Numbers with Asterisks
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.<br><br>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. Replace Numbers with Asterisks
See, it doesn't show up here.<br><br>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.<br><br>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.<br><br>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?<br><br>So we get a dollar 20 cpm. Create a CPM Custom Function (Create Better Calculators!) Getting Started Coding in Apps Script CPM Custom Function How to Count Views of Google Sheets
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.<br><br>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. Getting Started Coding in Apps Script Two Outputs, Same Cell
Input In the second one, we have two inputs.<br><br>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.<br><br>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. Getting Started Coding in Apps Script
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.<br><br>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.<br><br>Enjoy. Turn Your Apps Scripts into Native Formulas | Apps Script Custom Function Tutorial EASY Count First Digit of Cell
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.<br><br>Enjoy this. Hope you enjoyed creating your first script. Bye.</div> Getting Started Coding in Apps Script Automation is not Magic