One Million Checkboxes
In this video, learn how to create a Google Sheet with one million checkboxes that counts how many are checked by users in real-time. This project showcases the power of Google Sheets and Apps Script for collaborative tasks.
I saw this tweet and it's a one million checkboxes , it's a website, and when you check off a checkbox it checks it off for everyone and you can check on or check off. And there's this counter going on here, however many boxes are checked, so when it's checked on it adds one, if it's checked off it doesn't add it. And I said, this could be a Google Sheet. Well, I want to put my words to the test and actually create this as a Google Sheet. We're going to make this totally publicly available, uh, to everyone. Google sheet and we're going to count the boxes as they're checked. So let's do that. Let's go sheet dot new, create a new sheet. We'll call it one, call it one, one million check boxes. And the point is we're going to try to get to a million check boxes checked.
We don't need tables for this. We do want a bunch of columns, but we want those columns to be smaller, maybe 40, maybe less resize columns, like 20. That looks like a square. We'll insert, checkbox . We can actually take the entire column . Actually, let's take the entire sheet. Insert checkbox . I'll just do Command Y. And we have right now, it's a thousand rows. But I don't think we need a thousand rows. I think we need, like, something like 25. So let's delete all these rows down here. Delete rows 26 to 100. And we need more, uh, to the right. Thank you. I do want to make this a little bit bigger, I think.
Mmm, that looks fine. But we do want a row with no checkboxes, and we say however many are counted. So we'll say, here we'll format , we'll have these three be merged, as well as these. We'll call it checkboxes, checked. And then we will increase that a little bit more. There we go. And we'll put in a one here, however many are checked. So once we click, anyone clicks here, we want it to be checked off. So let's go to extensions app script . We're going to use an on edit function for this.
We're going to share this and make sure that anyone with the link is an editor because they need to edit this check boxes so they can come in here, check off a check box, and then this on edit will. work. So we use onEdit, we use this event, we're going to get the row of the event, so variable row. Actually we don't even need the row. Uh, all we need to know is if the value, new value is true or false. Um, because checkboxes are just a true or false here. So we just need to know if it's marked true. So new value equals E dot, I think it's new value. We can always look at onEdit, we can always look at onEdit.
Uh, events, uh, simple triggers, that's what we want. Here's the event objects, that's what we're looking for. And we have all of our options here, so this is open, this is change, here's on edit, uh, old value, all we need is new value, it's gonna be value alone, so it's just gonna be e. value. So we can look at this, actually, logger. log, and see what is the new value. Let's save this, make sure it's saved here, call it 1 million checkboxes, save that, and go and click a few of them, and in our executions we
should have the onedits here, and we'll log what the new value is. Might take a moment to log that. Let's do a few more. There it is, running, it says completed. Let's refresh. We should have some type of log here. Logger. log new value. Oh, this is supposed to be just value. I don't know how that got messed up. Okay, do that again. Do some of those check boxes.
Go back to our executions. Let's look at the top ones. Once it loads. So once it loads, it says true. There we go. So if it says false, we don't want to do anything. So if it says true, we do want to do something. So if, uh, we do also need variable count is equal to SpreadsheetApp . getActiveSpreadsheet. getSheetByName. We just want Sheet1. Actually, we might want to rename this checkboxes. There we go. We'll name this check boxes. We want to get range is a one get value. So every time we get, um, we need the count.
That's the count here. We don't actually need it until we need it here. And now we want, if new value is equal to true. This might need to change to something like true. We'll see if that works. Variable count is going to be there. We're going to say variable new count equals count plus one. And then we're going to take this same this thing here. Instead of set, get value, we will set value and we'll set the value to new count. Okay. So this should update that count every time we get a true here. Uh, this true is going to be a little wonky, so let's look at it.
Let's see if it's going to update it here. Does not look like it's happening. So we may need all caps true or we may need the text true. So let's test it a little bit more. We need text true here, save it. And there we go, so there it is. Now the count is coming up. Let's make it a little bit bigger. And let's change it to something like, uh, like Consolas in this case. So now every time we have a checkbox checked.
So one checkbox , even if we uncheck it, it's not adding. There we go. So now we'll add to the checkboxes every time this sheet, one million checkboxes is checked. I did want to test it with a new account, so I just signed into a different account, and I can, uh, edit these, and it also counts. But if I, Go to an incognito window. This is interesting. Is because I'm not signed in, I still can do the check boxes, but it doesn't seem to be doing the counting. It's not loading the Apps Script . So that's something very interesting to know about Google Sheets, is that when you allow anyone to edit a sheet, the Apps Script will not be loaded.
I think this is a safety feature for Google Sheets so that you don't, uh, have people who are not logged in loading, uh, possibly Uh, bad kind of, uh, Apps Script . So this is very interesting. So you need to sign in as a logged in user, and then it will load the Apps Script , and then it will load this on edit, uh, so you can actually add to the count. And before I make this public, I did realize that the Million Checkboxes website has a million checkboxes. It's not trying to count to a million. So, yeah, we will need, uh, our, uh, what is this, 70? Two more rows. Okay, two more rows. And now, 990 rows.
Oh, we added too many. So we're going to have a thousand rows. A thousand and one rows. But that's a thousand rows of check boxes. And we're going to try to create a thousand columns. So, insert 52 columns. So this is 52, we want 48 more. More. Insert 48. So now this is a hundred. So insert. So what we want to do is select the columns, insert 100 columns to the right. We're gonna do that now. That's once, twice, three times, four times, five times, six times, seven times, eight times.
So now let's see how many columns we have. If I select all the columns, I need to do it two more times. So now there's a thousand columns, and there's a thousand rows. So that's one million checkboxes . And you can see, these checkboxes are really struggling. It's gonna have to load all the way to the end here, to the right. In the bottom, or not, in the top right corner. And then it's probably going to, there, it's so slow, and
it might add number here. There, it, it did it very slowly, but it ultimately did add the, uh, number there. Oh, now it's doing it a little bit faster. It's got to get up to speed. And now you are able to get to this document. If you go to better sheets. co slash check boxes, check boxes, you will be redirected directly to this Google sheet, where if you are logged in to your Google workspace, you can check a box and we'll check it for everyone. It'll add to the check boxes checked and you can. Uncheck it as well, which it will not delete from that number . It'll just add all the times we're checking check boxes, but yeah, here's a million check boxes in a single sheet and it is going pretty slow.
Enjoy.