Automate Adding Prefix in Cell
Learn how to automate adding a prefix to cells in Google Sheets using formulas and Google Apps Script, making it easier to create unique identifiers for your projects.
So I wanna put in some word here and get out a prefixed word. So this word with a prefix on it, and in this case, maybe I wanna put the year here and create some kind of ID for tasks or for projects so I can do equals and take whatever is here and right before it go and, and put year today. That's today's date with a ampersand and a hyphen, and maybe I wanna put PROJ as in it's a project hyphen that, and now I can take this formula and automatically it's going to show up, but maybe I don't wanna show it unless there's some words here. So I can wrap this with if is blank, two commas, a two inside of that is blank. And now paste it all the way down.
And we'll only have it if we have some kind of word here, but what if I didn't even want this as a formula ? I wanted to just put in the word and it automatically does it on that particular cell. I'm gonna show you this automation go up to extensions app script . I. We're gonna change function by function to on edit with a capital E and an E here for event. And here we're going to get variable row equals E range . Get row. And if row is greater than one, meaning we're not on the meaning, we're not on the hetero, we're gonna execute something in these curly brackets. And what are we gonna execute? Well, we wanna get this project. We wanna get the variable value, which is e value. We're gonna go spreadsheet , app, get active spreadsheet , get range , row. And we're on column one.
Let's actually do it in column two for now. Set value, new word, and we're gonna create this variable. Variable. New word is equal to this, plus whatever value we had. And then we also need a variable of the year. So variable year equals new date. This is today's date. Get full year, and we're going to put year in front of that with a plus sign. So we're using a plus sign here, not an amp sign like we did in formulas. Let's save this and see how it goes. We're gonna go homemade. I think we need to just get the active sheet , not the spreadsheet , and let's, let's delete these and just write in. I. We can also add column here. So variable call equals e range dot get column. And if the row is greater than one two, ampersands call is equal to one.
So we are only editing when it's editing in the first column. So let's put in new project Manta Ray. Oh, and there we have Manta Ray Fuzz. And we get our 2025 Project Fuzz bucket. There you go. So now we're adding that prefix every single time we edit the first column and we get the row. We edit that word. There you go. Enjoy. I. 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.