Quickly Add Text In Front of Text with Apps Script

Learn how to automatically add text in front of existing text in Google Sheets using Apps Script, including creating a custom menu for easy access.

So you wanna add a little text in front of your text and you want to do it automatically. Say you want to indent these lists underneath maybe some sub-list, right? I would honestly recommend not doing this because we're adding spaces, but maybe you're adding some other kind of text. If you do want indent this, I might suggest doing something like this, moving those sub lists into another column. But for the purposes of this video. We're just gonna add a little text in front of the text, and we want to add a little helper function here that does this. So let's go to our app script . We are gonna need one thing first, which is our on open function , which will allow us to create a menu that's at Better sheets.co/snippets. We can delete some of this stuff and we only need one thing, which is, we'll add

a text menu and we'll say add spaces. We'll call this add spaces, so the user will see the two words add spaces, but it will trigger the function add spaces here. So let's create that function . So we're gonna need the active range spreadsheet , app. active spreadsheet dot range , get value. So we have the value of that. We can call this variable first. Value equals meaning we're just assigning that first value there. And then we're ultimately going to do spreadsheet app, do get active spreadsheet dot get range. So all of this again, and then we're gonna do dot set value. What is the value we're gonna set? It's gonna be of new value or new text.

New value equals first value, and right at the beginning we're gonna add in quotes, two spaces. We need a plus sign here, so let's save that and let's go test it. How we test this is we'll close it and we'll refresh our sheet. And right next to the help menu is our text menu and it says Add space. So let's go and select it and add a space. May have to authorize it the first time that we run it. I think we need to add, get active range . And not get active spreadsheet . So let's try that again. There we go. And we can do this as many times as we want. We can just add spaces. Again, we can add any text we want. So if we want to add that folder, let's create a new function add folder and just need to add a new item to our menu.

Add folder. Call this add folder. We can even show the emoji of the folder and add that at the beginning. So let's save this. And again, we're going to refresh our sheet so that our text menu has add folder. So let's say we want to add a folder here. New task. A new task list. Add a folder and we've added the folder to the beginning, so we've added some text in front of the text, and we do it with this menu here. Pretty cool, right? You can get this sheet and the script down below. Click down below for access to that sheet. 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.