Create Navigation Buttons in Sheets to Other Sheets

About this Tutorial

Add a button to go to another sheet inside your sheet.

Video Transcript

0:00 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.
0:10 I'm going to show you how in this video. This actually is only four lines of code, but we're going to retype all of this code line by line and create a new button for a new sheet.
0:19 So I'm going to 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.
0:37 I'm going to 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 going to do variable URL equals, in quotes, that URL that we just got.
0:57 Now, we're going to 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
1:29 the semicolon, the script is going to 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 quotes, double quotes around URL, and also plus signs so that we concatenate or put together these strings.
1:48 And before we end the script, just after we open that window, we go google.script.host.close, and then have those do that.
2:00 Parentheses at the end to execute it, and a semicolon, again, it is, ah, JavaScript. So how do we get this HTML in our sheet?
2:11 We do variable UI equals HTML service dot create HTML output, and inside of these parentheses we do our HTML right here.
2:23 But how do we get all of these to these variables together? We execute one line of code called spreadsheet app dot get UI parentheses dot show modal dialogue, and here we have two things.
2:36 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 and this one just so we know.
2:48 No, we're going to it. We're just so we know that we're using different function. So these are two separate functions.
2:54 They're just going to two different sheets. We're going to 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.
3:12 Same shape, but maybe different color, yellow, go to another sheet. We're just going to, this is going to be like any text we want.
3:22 It could even be a character, an emoji, anything. I'm going to make it a little bit smaller, just around there, save and close.
3:32 Now I can click once and drag this anywhere in my sheet. So maybe. I want to put it at the top in a header sort of place.
3:40 I can change the size of this and these three buttons right in the upper right corner. I'm going to assign script and here's where I'm going to paste my script name exactly as I type it, exactly the same, uh, capitalization and I can click okay.
3:56 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.
4:10 But if I click it, it's going to execute the sheet that go to the sheet. So let's do it. Run that script.
4:16 Opens the modal and opens the new sheet and there's our new sheet to go to exactly the same sheet as we have open.
4:23 It opens it. We can even close it. And then go to it again, go to another sheet, it automatically opens it in a new tab.
4:31 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.
4:38 You can copy paste it again, edit the function name. You must have different function names for different functions. And then edit the URL.
4:46 It could even go to a particular tab here using the GKE. ID 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.
5:04 Make a little button in there for it. Enjoy. I hope you enjoyed this.