Create Button in Sheets to Other Sheets
Learn how to create interactive buttons in Google Sheets that link to other sheets using a simple script. This tutorial walks you through the process step-by-step, making it easy to enhance your spreadsheet navigation.
let's create a button that goes to another sheet. So this button here goes to a totally other sheet, and we can make multiple buttons that go to multiple sheets. I'm gonna show you how in this video, this actually is only four lines of code, but we're gonna retype all of this code line by line and create a new button for a new sheet. So I'm gonna go to sheet new. We're gonna create a new sheet here. This is just new sheet to go to. And we want to get this URL. So go to extensions app script and that will bring up this here. I'm gonna create it from scratch here so you don't have to just copy, paste this function . Go to another sheet and in brackets we're gonna do variable URL equals in quotes, that URL that we just got.
Now we're gonna create a little bit of HTML variable, HTML equals, and in quotes, we have this sort of HTML characters that go around a script. We need to end that script as well. And then inside of the script we do window open, and here we use single quotes. And we're going to put a URL here and the semicolon, the script is gonna be JavaScript and we would put the URL right here, URL, but we have our URL as a variable, so we will need to put double quotes around URL and also plus signs so that we concatenate or put together these strings. And before we end the script, just after we open that window, we go Google dot Create Navigation Buttons in Sheets to Other Sheets script host close, and then have those parentheses at the end to execute it and. A semicolon again, it is, uh, JavaScript.
So how do we get this HTML in our sheet we do variable UI equals html service dot create html output. And inside of these parentheses we do our H TM L right here. But how do we get all of these variables together? We execute one line of code called spreadsheet , app, gi ui, parentheses, show modal dialogue, and here we have two things, ui, which is just this variable here, and then comma, and we say, go to another sheet. So this title is going to be different than this one.
Just so we know we're going to a, we're. Just so we know that we're using different function . So these are two separate functions . They're just going to two different sheets. I'm gonna save all of this. I want to copy and paste this function . Go to another sheet, exactly how it's written, because we're going to create a button over here. Insert drawing , and here let's create a new button. Same shape, but maybe different color yellow. Go to another sheet. We're just gonna, this is gonna be like any text we want. It could even be a character, an emoji, anything. I'm gonna make it a little bit smaller, just around there. Save and close.
Now I can click once and drag this anywhere in my sheet, so maybe I wanna put it at the top in a header of place. I can change the size of this. And these three buttons, right in the upper right corner, I'm gonna assign script. And here's where I'm gonna paste my script name exactly as I type it, exactly the same, uh, capitalization. And I can click, okay. If I want to execute that script, I just click the button. But if I don't want to execute the script, maybe I want to edit it, maybe there's some error . I'm holding down command key and clicking once, and here I get those three buttons again. But if I click it, it's going to execute. The sheet that go to the sheet.
Isn't that pretty cool? And you can run any number of buttons here to any number of sheets as long as you just keep using this same script. You can copy, paste it again, edit the function name. You must have different function names for different functions , and then edit the URL. It could even go to a particular tab here using the GID at the end. Really cool. Really fun way to add some interaction between your sheets that maybe you're. Executing some kind of financial analysis and you're like, Hey, I need to go check that sheet every single time. Make a little button in there for it. Enjoy. I hope you enjoy this.