Members-only tutorial

Watch the video and get the practice sheet with membership.

See membership options

Iterate Numbers with a Simple Apps Script

About this Tutorial

You're joining a company and they have some Google Sheets already created, and there's a sheet that has a cell in A1, this number, and you want to iterate it to 3, and B1 is connected to a lot of other stuff, so you don't want to mess with it. All you want to do is iterate a one, one at a time. I think the answer here is an Apps Script. 

Video Transcript

<div>0:00 So here's an interesting problem I just ran into. Say you are joining a Google Sheet, maybe someone shared it with you, or you're joining a company and they have some Google Sheets already created, and there's a sheet that has cell in A1, this number Learn how to work with numbers in Google Sheets effectively. Opens in new tab , and you want to iterate it to 3, and B1 is connected<br>0:17 to a lot of other stuff, so you don't want to mess with it. All you want to do is iterate a one, one at a time.<br>0:25 And you don't want to have to do this with so many clicks. Right?

I think it's like three or four clicks I'm doing right now.<br>0:30 Five, hit six, hit Enter, click again, hit seven. So that's like three clicks. Can I do this in a third of the clicks?<br>0:37 Can I save 66% of my time and iterate through? This number Learn how to work with numbers in Google Sheets effectively. Opens in new tab without affecting this B1 and without having to go through the entire sheet dealing.<br>0:47 Yes, I think the answer here is an Apps Script Discover how Apps Script can automate your Google Sheets tasks. Opens in new tab . And I'm gonna show you how to do that, but first I wanna change the background and everything of this.<br>0:54 I'm gonna use sheet styles and I'm gonna do this in one click.

You'll see I want to just, make it a little easier to look at.<br>1:03 There we go. But I'm going to go to Apps Script Discover how Apps Script can automate your Google Sheets tasks. Opens in new tab . Let's see what we have in Apps Script Discover how Apps Script can automate your Google Sheets tasks. Opens in new tab . I'm going to write a little Apps Script Discover how Apps Script can automate your Google Sheets tasks. Opens in new tab very quickly, in real time here.<br>1:11 And all we need to do is we need to do, I guess, two things. One, we can create a menu here, but then that's going to be the same amount of clicks like.<br>1:21 Three or four clicks, actually more clicks probably, to iterate this. But we wanna do a button here. So we can insert a drawing Find out how to use drawings in Google Sheets for interactive elements. Opens in new tab .<br>1:30 And let's do, let's do something like this shape.

Oh, actually. Let's just do this. Let's fill this in. There you go.<br>1:46 Save and close. There we go. We got our plus sign and we just want. To go into this little cell here.<br>2:05 Put it next to the cell. Maybe even make the cell bigger. But over here, we're going to be able to, on this three dots, on this drawing Find out how to use drawings in Google Sheets for interactive elements. Opens in new tab , we'll be able to assign a script.<br>2:15 What is that script going to be? It's going to be this. We're going to write it in real time here.<br>2:20 Get ready. It's going to be. Just open up app script Discover how Apps Script can automate your Google Sheets tasks. Opens in new tab . It's going to say function Understand the basics of functions in Google Sheets. Opens in new tab my function Understand the basics of functions in Google Sheets. Opens in new tab .

All we need to do is let's say add to a one, let's call it that.<br>2:32 We're going to get first off, we need variable number Learn how to work with numbers in Google Sheets effectively. Opens in new tab , equals spreadsheet Get insights into managing and manipulating spreadsheets. Opens in new tab app. We can use This IntelliSense here, we can just hit Enter, get active, spreadsheet Get insights into managing and manipulating spreadsheets. Opens in new tab , get sheet by name.<br>2:51 The sheet by name is gonna be sheet one, of course, because we haven't changed the sheet name Learn how to reference sheet names in your formulas. Opens in new tab , sheet one. We need also the range Explore how to define and use ranges in Google Sheets. Opens in new tab .<br>3:03 GetRange Understand how to retrieve data from specific ranges. Opens in new tab , a1, in quotes, and we need the value, getValue Learn how to extract values from cells in Google Sheets. Opens in new tab .

So this, all of this, just gets whatever number Learn how to work with numbers in Google Sheets effectively. Opens in new tab is in a1 and brings it here and we're going to do a variable new number Learn how to work with numbers in Google Sheets effectively. Opens in new tab .<br>3:18 It's going to be a little verbose. You probably can do it differently. It's going to be a little verbose. But this is going to be simple.<br>3:23 Variable new number Learn how to work with numbers in Google Sheets effectively. Opens in new tab equals number Learn how to work with numbers in Google Sheets effectively. Opens in new tab plus one. And what we want to do is we want to take all of this, paste it here, but we're going to change one thing.<br>3:36 We're going to change get value to set value. And the value we want to set is the new number Learn how to work with numbers in Google Sheets effectively. Opens in new tab . That is it.<br>3:43 Hit command S or hit save project up here.

And we can actually run this without having to assign it just to double check.<br>3:51 If there's any errors or anything, we might have to authorize it. We'll see in a hot second. Yeah, we do have to authorize here.<br>4:02 Select Dive into using query select clauses for data manipulation. Opens in new tab our account, allow, it's just editing and creating sheets with this spreadsheet Get insights into managing and manipulating spreadsheets. Opens in new tab app function Understand the basics of functions in Google Sheets. Opens in new tab . That's all we need. Let's see, we iterated the number Learn how to work with numbers in Google Sheets effectively. Opens in new tab .<br>4:14 Okay, so now take this name, this function Understand the basics of functions in Google Sheets. Opens in new tab added to A1.

The exact name that you named it, not the function Understand the basics of functions in Google Sheets. Opens in new tab , but the actual text.<br>4:22 Here add to a one going to click on the three dots of this plus sign a sign script and all we have to do is paste that text there click okay and let's see if this is going to work and there we go now we have just one click we are iterating a one and that's all we're iterating.<br>4:43 Of course, B one is changing because it's connected through many different sources, many different sheets, many different functions Get familiar with various functions available in Google Sheets. Opens in new tab and custom stuff.<br>4:50 But now we have a pretty cool little iterator here, really fun thing.

And if you're looking to iterate or add numbers to anything, this might have been very helpful for you.<br>5:00 If you're a better sheets member, down below Oh, at bettersheets.co is this exact sheet. You can copy it to your Google Drive.<br>5:08 And if you're not a member, become a member today. And if you're watching this on YouTube, go ahead and watch another video here.<br>5:13 There's tons of videos here about Google Sheets and doing cool stuff.

But also, check out Spreadsheet Get insights into managing and manipulating spreadsheets. Opens in new tab Automation 101, course to take you from zero, knowing nothing.<br>5:22 To knowing something about automating your Google sheets.</div>