How to Extract URLs from Hyperlinks in Google Sheets

Тәжірибелік нұсқаулар және стиль

Transform your data analysis: Support here for direct consults and premium content: ko-fi.com/hashalinz
In this Google Sheets tutorial I'll be showing you two main types of hyperlinks in Google Sheets and how to extract links from both types. This includes creating and using a custom function with Google Apps Script to extract URLs, even when you have multiple hyperlinks within a single cell.
In this video, we'll first learn how to create hyperlinks using the HYPERLINK formula and directly within a cell (Ctrl+K). Then, I will guide you through the nuances of these two methods and demonstrate how to extract URL data from both using the FORMULATEXT function and a custom script.
The script I've shared here is one I've seen used online from here: www.oksheets.com/extract-hype..., but I noticed it could us some improvements. The initial script had issues with case-sensitivity and required you to completely rewrite the formula in case of an error. I've improved the script to handle these issues more efficiently, and you can see the improved results in the video.
Finally, I take it a step further by showing how to extract multiple links from a single cell, a unique feature of Google Sheets. You'll also see how to modify the script to transpose the URLs into a row. Here's the final script: script.google.com/d/1-RxfEgtF...
Make sure to let me know in the comments if this video has been helpful and give it a like. Your feedback helps me improve and deliver more useful content.
----------------------------------------------------------------------------------------------------
⏳ TIMESTAMPS
----------------------------------------------------------------------------------------------------
0:00 The two types of links in Google Sheets
0:31 Extracting links from the HYPERLINK function
1:43 Original script I found online (link in description)
3:03 Problem #1: Case Sensitivity
3:43 Fixing the first problem
5:15 Problem #2: Multiple links
6:11 Fixing the second problem
7:40 How to transpose in Google Apps Script
8:07 Final result
----------------------------------------------------------------------------------------------------
💬 GOT A QUESTION?
↓↓↓ Leave a comment down below ↓↓↓

Пікірлер: 74

  • @user-bo5qb5fy8g
    @user-bo5qb5fy8g5 ай бұрын

    Really helpful, thanks for a clear, no nonsense tutorial that does what it says.

  • @vernon9096
    @vernon90967 ай бұрын

    Loving your videos. Thank you for sharing!

  • @sam_oml
    @sam_omlАй бұрын

    Absolutely helpful from start to end !!

  • @imogenblow9718
    @imogenblow97185 ай бұрын

    This was perfect, thank you!!

  • @veronikas710
    @veronikas7104 ай бұрын

    Thanks! Very helpful

  • @KrystalPalyu
    @KrystalPalyu2 ай бұрын

    Saved me hours - thank you!

  • @астепанов
    @астепанов5 ай бұрын

    Thank you very much! It perfectly works!!!!!

  • @enyeone
    @enyeone9 ай бұрын

    This video greatly helped sir, saved a ton of time. I don't understand anything in these scripts, just copied your code and it magically works. THANK YOU

  • @HashAliNZ

    @HashAliNZ

    8 ай бұрын

    Glad it helped!

  • @BigBoyAdvance
    @BigBoyAdvance5 күн бұрын

    Thanks, works great. I don't understand why google doesn't have a built-in function for this.

  • @Ghostkashak
    @Ghostkashak10 ай бұрын

    Thanks for the useful script. Save a day!

  • @HashAliNZ

    @HashAliNZ

    8 ай бұрын

    Glad it was helpful!

  • @drewclifton610
    @drewclifton6106 ай бұрын

    Well played; thank you!

  • @tedtimetrek
    @tedtimetrek4 ай бұрын

    great video!

  • @siarheipilat8152
    @siarheipilat81526 ай бұрын

    Nice, thanks!!

  • @mister_maxwell
    @mister_maxwell6 ай бұрын

    Very very good. I have to make a python crawler and now i can finish my project in case of your tutorial. Many thanks - it saved me lot of time. **********

  • @aruna.k9117
    @aruna.k91175 ай бұрын

    Perfect👍

  • @jurischmidt940
    @jurischmidt9402 ай бұрын

    Thanks a lot

  • @mudassar1
    @mudassar19 ай бұрын

    Thank you so much.

  • @HashAliNZ

    @HashAliNZ

    8 ай бұрын

    You're welcome!

  • @Bagsalwayspacked
    @Bagsalwayspacked9 ай бұрын

    Thank you! I've been trying to do this for ages but all the other scripts I found didn't work. Just wondering if there is a way to use a variation of this script in google docs. So the script runs through a document and then exports the links URL and anchor text to a spreadsheet

  • @khanhasan7933
    @khanhasan793322 күн бұрын

    Really helpful

  • @HashAliNZ

    @HashAliNZ

    22 күн бұрын

    Thanks!

  • @Elisummit845
    @Elisummit8454 ай бұрын

    Great videos thank you, has helped me a lot (I'm not very savvy in this). I'm working on a project and I'm trying to extract a hyperlink from 1 column, column C, and put it into another column, D but within Parenthesis of column D. Is there a formula for that?

  • @florenl8157
    @florenl81572 ай бұрын

    life saver

  • @arielo61
    @arielo616 ай бұрын

    hi! great video!!!. there is a way for open all the url at same time, with a iteratite script? thanks!

  • @user-qk3mb7sc5e
    @user-qk3mb7sc5e10 ай бұрын

    This was so helpful! Quick Question toward the end of the video when you have a cell with multiple hyperlinks. Like you mentioned, if you have many rows of data, the different links with collide. However, I also am working with data that also has a lot of columns, so doing the transpose (or updating the function to do so) is also not feasible. Is there a way to display the individual urls still within only one cell as to not change the original row/column dimensions?

  • @HashAliNZ

    @HashAliNZ

    10 ай бұрын

    Hiya. Unfortunately I'm not near a computer for the next few weeks so I can't test, but perhaps something like this might work: =join(", " , geturl(B8))

  • @danielsneighborhood2050
    @danielsneighborhood20506 ай бұрын

    Hello, I'm attempting to find an easy way to directly link cell to cell with a hyper link. For instance, I want cell H11 to link me to nots in HH11, and HH12 to Hyper link me "back" to H11. I want to expand this to all my cells in an easy way. I want this same hyper link function, because it can be interchangeable with other sheets. The issue is easily getting the values to expand, instead of changing each link. The hyperlinks to google don't reveal a pattern that is practical to change either. I just want to link to the same line, H11 to HH11, and back, all the way down the document to H1000, etc, to HH1000 etc. Can you help me out?

  • @myofficeonline5680
    @myofficeonline5680Ай бұрын

    I don't know what I'm doing wrong, i don't see a list of sheets to choose from when I'm trying to create a link (internal link) kinda like a table of contents that I'm trying to do. Any help would be greatly appreciated.

  • @tamyboy1
    @tamyboy18 ай бұрын

    Thank you Hash(im?) Ali sir!

  • @HashAliNZ

    @HashAliNZ

    8 ай бұрын

    Most welcome!

  • @bonnylisking1430
    @bonnylisking14307 ай бұрын

    Hello thanks for sharing the script, but I'm getting error if the hyperlink is in the same google drive for example image link uploaded in the same google drive. Anything I can do to fix this? #ERROR! TypeError: Cannot read properties of null (reading 'getRuns') (line 6).

  • @workaccount12345

    @workaccount12345

    2 ай бұрын

    I'm having the same issue. Have you fouund a fix??

  • @jeffreytang888
    @jeffreytang8882 ай бұрын

    it works on my google sheet, tqvm for the awesome script 🙏 In a multiple hyperlink cell, is there a way to extract only one single URL hyperlinked to a specific word, say for example 'view' ?

  • @HashAliNZ

    @HashAliNZ

    2 ай бұрын

    Yeah, we can do that. This script takes in two arguments: cell and text. When you use the custom function in the spreadsheet, you have to put the cell in double quotation marks, and the text is case sensitive. So for example, =geturl("B8","view") If you want the cell reference to be dynamic so you can copy it down, use =geturl("B"&row(),"view") Here's the script: function getURL(cell, text) { var myRange = SpreadsheetApp.getActiveSheet().getRange(cell); var richTextValues = myRange.getRichTextValue().getRuns(); var urls = []; for (var i = 0; i var url = richTextValues[i].getLinkUrl(); var textRun = richTextValues[i].getText(); if (url) { if (text && textRun.indexOf(text) !== -1) { return url; // Return the URL immediately if the specific text is found } urls.push(url); } } if (text) { return null; // If text is specified but not found, return null } return urls; // Return all URLs if no specific text is specified }

  • @jeffreytang888

    @jeffreytang888

    2 ай бұрын

    @@HashAliNZ i've just tested this and it works perfectly, tqvm bro, u r amazing ! 🙏👍😃

  • @user-vg9fg6cy6b
    @user-vg9fg6cy6b9 ай бұрын

    Can you copy-paste the final script into the description box above? Thanks

  • @HashAliNZ

    @HashAliNZ

    9 ай бұрын

    Hi Laura, I can't as KZread doesn't allow certain characters in description boxes. But I'll give you the code here: function GetURL(input) { var myFormula = SpreadsheetApp.getActiveRange().getFormula(); var myAddress = myFormula.replace(/=.*?\(/,'').replace(')',''); var myRange = SpreadsheetApp.getActiveSheet().getRange(myAddress); var richTextValues = myRange.getRichTextValue().getRuns(); var urls = []; for (var i = 0 ; i var url = richTextValues[i].getLinkUrl(); if (url) { urls.push(url); } } return [urls]; };

  • @djerekkayzakian-rowe
    @djerekkayzakian-rowe6 ай бұрын

    Hi Hash, Thank you so very much for this script! Your video was very clear and concise. I have found one scenario that seems to break the functionality and that is to add rows above: If I have, e.g., three rows in which C2, C3, and C4 are retreiving the URLs from A2, A3, and A4, then I add two rows above row 2, C4 and C6 will now both display the URL from A6, and the URL for A4 does not display anywhere. When uswing GetURL, my workaround has been to delete the entire column containing the GetURL formula, add rows above, reenter the GetURL formula, then drag it to the bottom of the sheet; it works, but it's cumbersome. Is there any way to alter this script so that it can accommodate the additon of rows above and still reference the intended cells? Thanks so much again!

  • @HashAliNZ

    @HashAliNZ

    6 ай бұрын

    Huh, I never tested that. One solution would be to recalculate all formulas. Doing that manually won't work because the data will be cached, so we can create a new script to do the recalculation for us. I haven't had a chance to test it, but I think this *should* work. It's my go-to recalculating script when I have cached formulas: script.google.com/d/105t_qQhmLowS8FdjLig4iq3UMkZhIGIx9-D951iCJrhh0jv9tAEgllFm/edit?usp=sharing

  • @djerekkayzakian-rowe

    @djerekkayzakian-rowe

    6 ай бұрын

    @@HashAliNZ Thanks for getting back to me! I'm completely new to scripts, so I'm not sure how to implement this. I went into Apps Script and added the recalculateFormulas script, but I'm not sure how properly to execute it after that. I tried =recalculateFormulas(geturl(A4)), but that came up with an error.

  • @HashAliNZ

    @HashAliNZ

    6 ай бұрын

    @@djerekkayzakian-rowe Oh sorry! In your Sheet with the links, click on Insert > Drawing. Then add a rectangle or something to act as a button. Add some words to it, something like "Reset formulas" or something like that. Click on Save and Close and place it where you want it in your Sheet. Then click on it, click the three dots, and click on "Assign Script". When the popup box comes up, type the name of the function (in this case, recalculateFormulas). Then save that and click the newly made button. It'll run by itself (you might need to authorise it - if you do need to, then click it again after it's been authorised)

  • @djerekkayzakian-rowe

    @djerekkayzakian-rowe

    6 ай бұрын

    @@HashAliNZ Thanks so much Hash! Very cool how that works; I had no idea you could create custom buttons like that. I did create the button and try it, but it's still getting the wrong url when you add rows above then run that script. I so appreciate your help, and it's no big deal if this is not possible!

  • @HashAliNZ

    @HashAliNZ

    6 ай бұрын

    @@djerekkayzakian-rowe Ah bugger! I was really hoping that would work. I'll test out a few other things later tonight and let you know if I find anything!

  • @dini.alejandro.eyecue
    @dini.alejandro.eyecue3 ай бұрын

    any way to extract the link for the second case? a link without hyperlink formula?

  • @HashAliNZ

    @HashAliNZ

    3 ай бұрын

    Yes, the video is showing how to write the script to extract it

  • @user-vg9fg6cy6b
    @user-vg9fg6cy6b9 ай бұрын

    My Google Sheet can not recognize the script I created. How do I link the GSheet to the GetURL()? Thanks

  • @HashAliNZ

    @HashAliNZ

    9 ай бұрын

    Hi Laura, This happens in the myRange variable using the getActiveSheet() function. Here's the full and final code if you need it: function GetURL(input) { var myFormula = SpreadsheetApp.getActiveRange().getFormula(); var myAddress = myFormula.replace(/=.*?\(/,'').replace(')',''); var myRange = SpreadsheetApp.getActiveSheet().getRange(myAddress); var richTextValues = myRange.getRichTextValue().getRuns(); var urls = []; for (var i = 0 ; i var url = richTextValues[i].getLinkUrl(); if (url) { urls.push(url); } } return [urls]; };

  • @dineshgoel6394
    @dineshgoel639411 ай бұрын

    hI i tried the script , but it shows Error Exception: Range not found (line 4).

  • @HashAliNZ

    @HashAliNZ

    11 ай бұрын

    Hi Dinesh! Once you have your script, you don't need to hit the Run button. Just save it, then go back to your spreadsheet and start writing your custom function =GetURL(B4)

  • @dineshgoel6394

    @dineshgoel6394

    11 ай бұрын

    @@HashAliNZ i tried as you suggested , but the problem still persists, sharing my file link, could you please have a review docs.google.com/spreadsheets/d/1ZYLjo2niA2_k7Nabtu7QtJTjmpQhhoS9OqnKyHlGlcE/edit#gid=0

  • @dineshgoel6394

    @dineshgoel6394

    11 ай бұрын

    @HasAliNZ , I think i figured the problem , the label I assigned to the URL is not a text, but is a number . So could you please help with a script that works with number & text both ?

  • @HashAliNZ

    @HashAliNZ

    11 ай бұрын

    @@dineshgoel6394 Hey Dinesh, The way the function works is to extract the hyperlink from the richTextValues. Google Sheets doesn't store numbers as a rich text value (and we can't force it to - I tried using two different methods but both failed). Since numbers aren't rich text values, we cannot extract the hyperlink from it. The easiest way to create a fix is to turn adjust your number so it becomes a rich text value. For example, if your number is 456, then change it to something like 456x. There are other options like incorporating metadata (like notes), but the option I gave before is by far the easiest for data entry.

  • @DanHeginbotham

    @DanHeginbotham

    10 ай бұрын

    You may have had the same issue as me - I removed the word "input" from (input) in the first line in the script and then it worked: function GetURL() { var myFormula = SpreadsheetApp.getActiveRange().getFormula(); var myAddress = myFormula.replace('=GetURL(','').replace(')',''); var myRange = SpreadsheetApp.getActiveSheet().getRange(myAddress); return myRange.getRichTextValue().getLinkUrl(); };

  • @muddasserawan3185
    @muddasserawan31852 күн бұрын

    I wanted to give it a thumbs up, but that would change it 405 from 404. I love your work but 404 is fun.

  • @HashAliNZ

    @HashAliNZ

    Күн бұрын

    🤣🤣🤣

  • @karelvanbiervliet1181
    @karelvanbiervliet11816 ай бұрын

    When I tried the original code, it just gave me blank cell

  • @HashAliNZ

    @HashAliNZ

    6 ай бұрын

    Here you go: script.google.com/d/1-RxfEgtFhU0rhRjUkMNSUWc8jLjCGnT5DBTptsUztD9jS3ZuBaVckPXX/edit?usp=sharing

  • @zukonarya
    @zukonarya3 ай бұрын

    Please Help, does NOT work. The cell says #NAME? and comments Error Unknown function: 'getURL'.

  • @HashAliNZ

    @HashAliNZ

    3 ай бұрын

    If you didn't follow the video all the way through, then you'll need to ensure the function getURL has the same cases (upper case and lower case) as the script name. If you did all the way through, then you'll see how to fix this.

  • @karelvanbiervliet1181
    @karelvanbiervliet11816 ай бұрын

    Thanks Ali for this. But you only provide the original script to copy and past. Would be easier, I believe, if you would leave the code in the remarks so dislectic people can also copy and past it 🤣

  • @HashAliNZ

    @HashAliNZ

    6 ай бұрын

    Fair point, Karel! Here you go: script.google.com/d/1-RxfEgtFhU0rhRjUkMNSUWc8jLjCGnT5DBTptsUztD9jS3ZuBaVckPXX/edit?usp=sharing

  • @MuhammadUsman-dk4kt
    @MuhammadUsman-dk4kt7 ай бұрын

    plz give me answer ASAP

  • @HashAliNZ

    @HashAliNZ

    7 ай бұрын

    Sorry I don't see your question anywhere. How can I help?

  • @MuhammadUsman-dk4kt

    @MuhammadUsman-dk4kt

    7 ай бұрын

    your code is only working where sheet cell value has English Alphabets but I have integers in sheet cell.... like 1 then 2 then 3 How can i get that ? Below is your code Function GetURL(input){ var myFormula = SpreadsheetApp.getActiveRange().getFormula(); var myAddress = myFormula.replace(/=.*?\(/,'').replace(')',''); var myRange = SpreadsheetApp.getActiveSheet().getRange(myAddress); return myRange.getRichTextValue().getLinkUrl(); };

  • @MuhammadUsman-dk4kt

    @MuhammadUsman-dk4kt

    7 ай бұрын

    any update ??

Келесі