URL Link to Last Row
Learn how to create a dynamic URL link to the last row of your Google Sheets document, ensuring that the link always directs users to the most up-to-date data.
So here's an interesting little problem. I want to create a URL link to the last row of this document, sales or or sheet. Now what we can do is we can go to row 2 24, which is now the current URL, sorry. Now the current last row, I can right click and I can save you more cell actions and I can get linked to the cell. What that actually gets is the range . So let's actually add one more row and then I think I can show you this here. This is like the whole URL of the sheet, but at the end it says A twenty two hundred and twenty four. So this GID part is the U, um, the actual ID of the tab,
and then it adds and range a. 2 24. So if I give this to someone, this is not actually quote unquote giving them the access to the last row, it's giving them the link to exactly this range . So if I add a bunch more cells , let's say add a thousand more cells . And I add handy down here. Now, this is the last row of data here, 1218, but I've given them the URL that has a 224 that URL never changed. Maybe the answer is, let's put a last row as a named range . But unfortunately this URL uh, getting you to a specific
range is not going to accept. A named range . It's only a one notation . It's only gonna be a 5, 4, 5, uh, four colon, four if it's the fourth row, C, colon C. If it's the C column, it could only access a certain actual a one notation range . So my solution to this would be to create a helper, sort of a helper sell or a helper sheet . Either it could be up here at the header . That says basically, here's the last row. Or it could be another tab that says, last row sales, for example, and let's just put a one here. We're just delete all, everything except one cell, and this
cell won't change this cell. I can say, Hey, go to la. Go to this URLI can. Get this actual link to the cell. I can do this, A one on this sheet, which is the GID. This URL will always bring someone to last row sales sheet, A one, no matter what, as long as they have access to it. And now I want to create something that brings them to whatever the last row is in Salesforce. So I can do that actually fairly easily with App Script . So I'm gonna go up to app script and I'm gonna write a little function . Now we can get the URL of this sheet and all we need to do is add em,
percent range equals, and we need to get the A one notation of that. Range . So again, right now it's 1218, but let's put in like we haven't updated it yet, so we'll have 2 24 there. So we say a 2 24. That's the current URL. If I click it, I'm gonna be taken here, but I really want the last row and I wanted to edit all the time. So let's add a little bit of function here. And this function I'm gonna do on edit because every single time we edit something, I want it to update. In case I add a row in case I do something, uh, add some value there on. By the way, on edit only , only triggers when you change the cell value, not
actually the structure of the sheet. That's on, on change. But let's do on edit because we want to add a cell value there. And then boom, that's the last, that's the last row. So our current URL is, is this, uh. But let's take this 2 24 off. So we're gonna say A, we wanna go to the A column and then we want to go to some row. Let's get the last row of sales and that's gonna be variable. Last row equals spreadsheet . App. Do get active spreadsheet , get sheet by name. Sales. Get last row.
And let's check this. I'm gonna do logger log last row. We're going to be, actually, we can probably run it. We will need to review and authorize it the very first time we run it. So actually let's change this name to something else. For now, we just want to get this last row and look at it and say, is it gonna be something? There's authorization ? Oh, I think I need a capital R on get last row there. So now it's 1218. Let's go and double check. That is exactly it. Yes, it is 1218. It is looking at this and if there's any formulas here, if there's any extra data like formulas across here, it'll get the, that last row. So it might be 1225. It's okay, whatever the last row is, it will.
Bring us to the last row or get that number . So that is good to check there and that we had that capital R. And we do want this to be on edit with some event. Actually, we don't need to know where we are 'cause we just want to edit this all the time. So we have the last row and we have the ORL. All we need to do now is go to last row sales A one and put that in. So we're gonna say spreadsheet app that get active, spreadsheet , get sheet by name. And again, it is called Last Row sales, whatever the name of your sheet is, in quotes here. Get range is, in this particular case, a one. We're just editing the sale of a one and we're setting the
value is going to be URL plus. This variable last row. I wanna show you this a little bit easier. This is get range A one set value, URL plus last row. And that should work on every time we edit. So now let's do 1219. And we have a URL here. We can format this. Let's format this a little bit nicer. Uh, let's clip it. And there we go. Our range is a 1, 2, 1 9. So let's click it and we go there. So every time we edit, okay, we're adding a new row here, 1225. And it is updated here. It's updating fairly quickly now because there's not much happening on the sheet. If your sheet has a lot of functions , a lot of things running, may take a
moment or two, but shouldn't take too long on edits do happen fairly quickly. Uh, this is very, very exciting that now I can say, Hey, go to this cell, and it'll always bring you to the last row little helper function to get that you are a link to the last row. A little help. That we need to help you. We need to help Google Sheets that to do this for us because it's not doing it for us now. Thanks. If you wanna learn more app script like this, check out my Udemy course. Spreadsheet Automation 1 0 1 or that spreadsheet , automation 1 0 1 is on Better sheets.co. And you can buy it standalone without buying a membership over at Udemy. But go check out spreadsheet automation 1 0 1 over on Better Sheets.
I go deep into some really, really cool app scripts that you can do right now very quickly. 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.