Members-only tutorial
Watch the video and get the practice sheet with membership.
About this Tutorial
Sheet Resources
Video Transcript
<div>0:02 Hey, so we're gonna try to turn background color Learn how to work with background colors in your spreadsheets. Opens in new tab into text. I thought this would be an interesting process here because there is no formula Understand the syntax used in Google Sheets formulas and scripts. Opens in new tab to say what's the background color Learn how to work with background colors in your spreadsheets. Opens in new tab here.<br>0:13 And a lot of times when we're cleaning up data Explore how to manage and manipulate data in Google Sheets. Opens in new tab in sheets, we get data Explore how to manage and manipulate data in Google Sheets. Opens in new tab that looks like this where Discover how to use the WHERE clause in your queries. Opens in new tab someone has gone by hand and colored in some array of data Explore how to manage and manipulate data in Google Sheets. Opens in new tab .<br>0:23 But we want actual, like, data Explore how to manage and manipulate data in Google Sheets. Opens in new tab from this.
We don't want it just to be visually pass or fail this bread for fail and green for pass, of course.<br>0:32 We're going to use Apps Script Get started with Google Apps Script for automating tasks. Opens in new tab , haven't written Apps Script Get started with Google Apps Script for automating tasks. Opens in new tab yet, so let's do that right now. First off, let's get the actual background color Learn how to work with background colors in your spreadsheets. Opens in new tab of these.<br>0:41 So this is, let's look at this. This is the heck code he- f- f- f- f- so we'll write that here as a note Find out how to add and manage notes in your spreadsheet. Opens in new tab .<br>0:49 Variable red equals f- f- f- 0- 0- and then what's this green? Let's get this green. 0-3.
Just so we have these available.<br>1:05 To us, once we need them what we want to do is let's get the background color Learn how to work with background colors in your spreadsheets. Opens in new tab of, let's say C2, just to see that we can actually get the background color Learn how to work with background colors in your spreadsheets. Opens in new tab .<br>1:16 So variable vgcolor equals, I'm gonna do spreadsheet Learn about the structure and features of Google Sheets. Opens in new tab dot app, get active spreadsheet Understand how to access the active spreadsheet in Apps Script. Opens in new tab , get ring get sheet by name, I think it's just gonna be sheet one, sheet one, actually this we'll call this.<br>1:37 Sheet one, then we'll do, we're gonna get this out of the way we're gonna call bg.
Color equals sheet one dot get range Learn how to define and work with ranges in Google Sheets. Opens in new tab , we want to just see two.<br>1:53 And I think we can get get background, I think. Let's see what that does. Let's go. Logger.log bgcolor. Go get bgcolor.<br>2:22 Let's just run this and see what happens. We're gonna have to have permissions, of course. What I like to do in this process is just sort Discover how to sort data effectively in your spreadsheets. Opens in new tab of get this piece by piece instead of having to do the entire thing all at once.<br>2:36 And so what we do is we got bgcolor fff00. Let's double that as correct. And in our background color Learn how to work with background colors in your spreadsheets. Opens in new tab we sort Discover how to sort data effectively in your spreadsheets. Opens in new tab of forgot this hashtag or hex code.<br>2:50 We now want c3.
And let's see what that looks like. We do this just to double check that we can.<br>2:57 Get this color, background color Learn how to work with background colors in your spreadsheets. Opens in new tab . CC. Let's change it to c3. Save it, run it, and hopefully yes. Well, would it.<br>3:14 Do we get the wrong hex code? C3. Let's see what that is. I guess we did get the wrong one.<br>3:23 That's good that we double checked. Or did I press the wrong button there? I don't know.
But that's good that we double checked the background color Learn how to work with background colors in your spreadsheets. Opens in new tab .<br>3:32 So now, what we can do is basically go through all this data Explore how to manage and manipulate data in Google Sheets. Opens in new tab , the C2 down to what we got into C, 347.<br>3:41 We got 347 grades to give people. All right. How do we do this? Well, we'll get the variable cells Understand how to manipulate individual cells in Google Sheets. Opens in new tab . That'll be an array of sheet1. getRange Learn how to retrieve a specific range of cells in your spreadsheet. Opens in new tab C2 colon actually in quotes C2 colon C3 4 7.<br>4:07 That's the cells Understand how to manipulate individual cells in Google Sheets. Opens in new tab . And actually we want, let's call this colors. GetRange Learn how to retrieve a specific range of cells in your spreadsheet. Opens in new tab . getValues Find out how to get values from a range of cells. Opens in new tab . And what this is gonna look like is an array again.<br>4:19 Let's just log this and look at what it is again.
I like to do these logging just to see what we get.<br>4:30 There we go. We get nothing. Okay. Because we get with these our values Explore the different types of values you can use in Google Sheets. Opens in new tab . Oh, that's, that's actually a really good point.<br>4:37 We need to get each of these cells Understand how to manipulate individual cells in Google Sheets. Opens in new tab . We need to get the background color Learn how to work with background colors in your spreadsheets. Opens in new tab here. So we need to say git range Learn how to define and work with ranges in Google Sheets. Opens in new tab .<br>4:44 Okay. Gotcha. But now we have, okay, we will call the cells Understand how to manipulate individual cells in Google Sheets. Opens in new tab and we will.
Say for we'll do a for loop here for I equals zero semi colon cell I is less than cells Understand how to manipulate individual cells in Google Sheets. Opens in new tab that link semi colon I plus plus we'll do.<br>5:07 For loop through the eyes and what we're going to do we're going to go cells Understand how to manipulate individual cells in Google Sheets. Opens in new tab I oh wait, this is going to get us the.<br>5:23 Value okay, so let's actually create variable colors equals it'll be a blink one and we'll say colors dot push. Shh.<br>5:39 A color, I think we need to put this in semi maybe not, maybe we do. Let's check.
Let's actually do this but for colors what are we gonna push the color up?<br>5:55 Of the color, variable color equals sheet one dot get range Learn how to define and work with ranges in Google Sheets. Opens in new tab .
The first one is the row so it'll be one, no, two.<br>6:11 Two plus i because i is going to start as zero and go up and we want the second row second column because we are looking at, oh, c column so it's three column and we're only going to see one cell at a time so we're going to get this i range Learn how to define and work with ranges in Google Sheets. Opens in new tab and we're going to dot get background and that is going to be<br>6:32 the color of that cell and then we're going to push it but we're just going to look at what this is at the end.<br>6:39 This should be an array of all the things we might not necessarily need it because we just need to basically set a text here maybe let's say pass fail here as well and we just need to set this text.<br>6:55 But let's look at this logger dot before we do our stuff we'll look at this logger dot log colors again i like to just look at these things in the log and see if we're getting everything correctly perfect so now we have all we now we can actually graph Learn how to create and customize charts in Google Sheets. Opens in new tab all of the colors but we don't actually need an <br>7:18 array of colors we just need to execute what we're doing so let's delete this let's delete colors we got color and now if color is equal to this red that is fail right so we are going to get this range Learn how to define and work with ranges in Google Sheets. Opens in new tab so we're going to do sheet one dot get range Learn how to define and work with ranges in Google Sheets. Opens in new tab two plus I the column we need is four because we're gonna<br>7:50 write that there four one one dot set value and the value we're gonna set is fail now underneath this if if Have a great day.<br>8:05 We're gonna actually do the exact same thing that if and instead of this color, we're gonna look look at that green if it's equal to that green, we're gonna say pass.<br>8:20 There is something the matter.
Oh, I see. We didn't need elses, we just need another quote here. We don't need these elses.<br>8:54 We just need a couple of ifs because if neither of these are true, it just won't do anything. We just don't care.<br>9:00 We only care if it's one of these two colors. So now this should, based on just running this once, we are going to be able to put pass fail into each of the d column where Discover how to use the WHERE clause in your queries. Opens in new tab it is here.<br>9:13 So let's see if it works. There we go. Fail pass, fail pass, fail pass. Perfect.
We only need to do this once and we are done with our Let's just double check that it's working correctly, right?<br>9:28 We're already on 50. Here we go. We're almost at 100 now. We're past 200 and here we go. We are at the final all passes.<br>9:38 We've now graded</div>