Square Cell
In this video, learn how to create square cells in Google Sheets using Apps Script, making your dashboards visually appealing and easy to manage. Discover how to automate cell resizing with a custom menu for enhanced functionality.
I was looking at this dashboard concept that I created with square cells , and it actually is very beautiful, with different colors and squares. But I was wondering, like, it's not that easy to create a square cell, but can we do that easier? Let's show you I'm gonna create a brand new sheet . I'm gonna call it Square Cell And I'm gonna go up to Extensions, Apps Script . But before that, I'm gonna go over to bettersheets.co/snippets, which is available for free. There's a few of these custom functions that you can click on. You don't have to log in, you don't have to do anything, you can just copy them to your clipboard. And what this is gonna do is create a little custom menu , and we're gonna call it Square Menu, and that will create a menu in your sheet to do something. Because basically, we wanna go here, resize column , go over to the row, resize row , and change it to something other than 21 by 100 pixels, right? Which is, in this case, a square, we want 50 by 50 or 100 by 100, and we wanna do it in the cell we are in. Apps Script allows us to do all of this stuff, and it's really, really cool. So squareCell, we'll rename it here. We'll add an item, and the first part is gonna be what someone sees, Square this cell. And then the second part here is gonna be Square, with a capital C, cell. And then we're gonna write a function , and this function doesn't have to be very complicated or, or, or much. I'll show you the whole function . We're gonna get variable ss = SpreadsheetApp . activeSpreadsheet. That is just the file we're in.
We're gonna get the active range , and that's gonna be ss. activeRange Actually, we wanna get the sheet. Get active sheet here. And then once we get the range , we're gonna get the row, is gonna be activeRange.getRow, and variable col or column is activeRange.getColumn. So now we know what column we're in, we're, we know what row we're in, , SS And we're gonna set column width . The column width , the position we're in is column. The width is gonna be 100 'cause we just want it to be 100 by 100, or whatever you want. Then we're gonna do and again, we're gonna reference the row and 100. And it's really just these two lines of code that we have to do,
which is set the column to 100, set the row to 100, and done. But we're getting all of these variables here gonna save this. I'm gonna close my Apps Script , and I'm gonna refresh my sheet, meaning I'm gonna close it and open it again. When I do that, Gemini is gonna pop up, all this other stuff is gonna pop up, but what really we wanna make sure we have is this square menu. Square this cell. I said squared this cell, so I can edit that. But in D6, I'm gonna select , I'm gonna select square the cell. And I do need to authorize it the very first time I run it And there, it is done. C3, I want to square that. Do this again. And there, I've squared the cell. Pretty cool, right? That we can just execute this simple action based on where we are in the sheet.
And now I want to go back to my app script and edit that squared the cell. I can make any edits I want. See here, s- squared the cell. I just want square the cell. And I can even be more specific, active cell . There, let's do that. I'm gonna close this after, after saving it, I'm gonna close it, and I'm gonna refresh my sheet. And I only need to refresh when I make an edit to this particular menu. When… If I want to make an edit to the actual code, I do not need to actually refresh the sheet. But here now it says square the active cell . Boom, it's done. A really interesting way to add some automations or, or simple functions to your workflow
You're watching Better Sheets here on YouTube. You have two options here for your next video. Before you go, comment down below if you have any question whatsoever, and I'll make future videos from those questions. But for right here, right now, one of these videos could be your next Google Sheet