Auto Count Length
Learn how to automate character counting in Google Sheets using both a formula and Google Apps Script in this informative video. Discover how to streamline your workflow and eliminate the need for visible formulas.
you wanna automate the counting of the characters in a cell. So I'm gonna show you a formula and I'm gonna show you how to do this in app script . So here we have equals LEN for length, and we can put a two and we can copy and paste that down, but we're gonna get zero even if we have nothing there. So we could automate this or make it look a little bit magic by saying if in parentheses is blank, A two. And then put a couple commas and then and that, and now we have Blink. We have nothing until we type something in, something in there. 12 characters. But what if we don't want a formula at all? I'm gonna show you how to do that in an app script . Go to extensions app script , follow along. It's not as hard as you. We're gonna change our function to on edit. We'll name this automate count length. Our function on edit has an e or variable little, we can call it event.
You can put any word here you want. We'll put E. And it has some really cool information like variable row equals. E range get row so we know what row we're on and we know what sheet we're on. Just by going spreadsheet , app, gi, active sheet , parentheses, GI name, and if, and we'll put in parentheses sheet, equal sign data , which is the sheet we're on. Then we're gonna execute something in these curly brackets. And what are we gonna execute? Well, we need to get the value. So we'll do spreadsheet app, do get active spreadsheet , parentheses, get sheet by name. We get data get range . We'll go to the row we're on, we'll go to the first column, which is the A column, and we'll get value. Now getting the value is just getting what's inside of that cell. So we'll call this variable word equals.
And variable length is equal to word length. And now in order to put it into the B column, we're gonna take all of this that we just typed here that get value, we're gonna paste it. And instead of row and one or the A column, we're gonna put two. And instead of get value, we're gonna do set value, but what are the value we're gonna set? It's gonna be length, L-E-N-G-H, which is this variable here. We'll save this all without doing anything else. We'll go back and we'll type something more here. Hit enter. And we did have a formula here, but it actually got overwritten by this data . So let's delete all of this and I'm gonna say hello some more. Count me in. Please count me now, and each time I'm doing that, a length is coming in
and it's gonna be added automatically. Isn't that cool? We're automating the counting of all of these without using a formula by just using app script , and we don't see the underlying formula here, just in case you wanted to do that. That's how you do it. If you enjoy this kind of thing and you wanna learn more about programming, check out master spreadsheet automation over on Udemy. I'll put a link in the description. Or just keep watching videos here on better sheets on YouTube. You are watching better sheets here on YouTube. Make sure you check out this video or this video and subscribe right now to get more tips, tricks, how tos, get more out of your Google sheets than you ever have before. I'm excited to be making a ton more videos here. Ask me questions down in the comments and I will answer them in future videos. But for right now, right here, one of these videos is gonna
be your next Google sheet.