Extract URLs from Hyperlinks in Google Sheets (No Scripting)

Published on

Extracting hyperlinks or embedded URLs in Google Sheets is possible without relying on Google Apps Script (GAS).

It doesn’t matter whether the links are (1) formula-based links or (2) embedded links, the method will work flawlessly.

You can refer to the two types of links in Google Sheets as:

  1. Formula-Based Links: Created using the HYPERLINK function. For example: =HYPERLINK("https://infoinspired.com/", "InfoInspired"). These are explicitly defined in the cell formula and show the URL when using FORMULATEXT.
  2. Embedded Links: You insert these links using the Insert > Link menu option. These links embed in the cell or text and do not reveal the URL when using FORMULATEXT.

For example, if cell A1 contains a link, =FORMULATEXT(A1) will return the cell formula if it contains a formula-based link. If it doesn’t contain a formula, it will return #N/A.

This method allows you to copy a URL from a link in a cell, regardless of whether the link is formula-based or embedded.

Extract URLs from Hyperlinks Individually (Built-in Method)

Steps:

  1. Hover your mouse pointer over the link.
  2. A small box will appear with options to copy, edit, and delete the hyperlink.
  3. Click on the copy-link icon.
  4. Right-click any cell and select Paste.
Extract URLs from Hyperlinks or Embedded Links in a Column

The built-in method is impractical if multiple links are in a column, as copying the URLs individually is time-consuming.

Instead, we will use a workaround that you can easily perform in a few steps without needing knowledge of Google Apps Script.

This method also applies to both formula-based hyperlinks and embedded links.

For example, we’ll consider the range A2:A5 in the tab named “Sheet1” and extract the URLs into B2:B5 in that sheet.

Step 1: Publish the Tab “Sheet1”

In this step, we will publish the sheet on the web. By doing this, Google converts the spreadsheet data into an HTML format, hosts it on its servers, and provides a URL for access.

Publish Sheets to the Web
  1. Go to the File menu, click on Share, and select Publish to web. Be cautious about publishing sensitive data, as anyone with the link can view the published content. However, you can unpublish it at any time.
  2. Under Link, select the tab name (i.e., “Sheet1”) in the first drop-down and then select web page in the second drop-down.
  3. Click Publish.
  4. Once published, you will get a link URL. Copy that.

Step 2: Import Published Google Sheets Contents Back to Google Sheets

  1. In cell A1 in “Sheet2” of the same Google Sheets file, right-click and paste the copied URL.
  2. In cell B1 in “Sheet2”, enter the following formula and wait for it to return a list of all the href values (URLs) found within anchor tags in the given HTML document:
=IMPORTXML(D1, "//a/@href")
IMPORTXML formula extracts URLs from website links

Step 3: Extracting URLs

In cell B2 of “Sheet1”, enter the following formula and voila!

=ArrayFormula(IF(A2:A="",,
   TOCOL(
      SUBSTITUTE(
         LEFT(Sheet2!B1:B, SEARCH("&sa", Sheet2!B1:B)-1), 
       "https://www.google.com/url?q=", ""
   ), 3)
)

Formula Explanation:

  • The LEFT function extracts n characters from the left of the strings in Sheet2!B1:B, where n is determined by the SEARCH formula: SEARCH("&sa", Sheet2!B1:B)-1.
  • The SUBSTITUTE function replaces “https://www.google.com/url?q=” in the values extracted by the LEFT function with “”.
  • The TOCOL function removes errors and empty strings from the output.
  • The IF function removes values in the TOCOL output if the corresponding rows in A2:A are blank.

That’s how we can extract multiple URLs from hyperlinks in Google Sheets.

Resources

Prashanth KV
Prashanth KV
Your Trusted Google Sheets and Excel Guide Prashanth KV brings a wealth of experience in Google Sheets and Excel, cultivated through years of work with multinational corporations in Mumbai and Dubai. As a recognized Google Product Expert in Docs Editors, Prashanth shares his expertise through insightful blogging since 2012. Explore his blog for practical tips and guidance on maximizing your spreadsheet skills.

Compare Two Tables for Differences in Excel

To compare two tables with similar data for differences, you can use the XLOOKUP...

Calculate Weighted Average in Pivot Table in Google Sheets

You can calculate a weighted average in a Pivot Table using a custom formula...

Summarize Data and Keep the Last Record in Google Sheets

In Google Sheets, we can summarize data (like sum, average, min, max, count) using...

How to Retrieve the Last Record in Each Group in Excel

As part of data analysis, you may need to retrieve the last record from...

More like this

Calculate Weighted Average in Pivot Table in Google Sheets

You can calculate a weighted average in a Pivot Table using a custom formula...

Summarize Data and Keep the Last Record in Google Sheets

In Google Sheets, we can summarize data (like sum, average, min, max, count) using...

Filter Data with Multi-Select Drop-Downs in Google Sheets

If you've started using multi-select drop-downs in Google Sheets, you may encounter challenges when...

15 COMMENTS

  1. Hi Prashanth,

    I was looking to get the ‘Sheet3’ url into a cell A1 with only formula (without script).

    Thank You.

  2. This worked, thank you!

    (Note: It does not work if you’re signed in to your company’s Gsuite account. Make sure to sign in to your personal Google account before starting the steps).

  3. Prashanth,

    So, I tried a couple of different things. The sheet I was trying to copy had around 1900 rows of URLs.

    Seems like the largest number of rows it will work with is around 1000

    To get it to work, I had to break it up into two sheets and just run the process twice.

    Pat

  4. Prashanth,

    I did everything as outlined above for Google Sheets. When I went to Step 3 it returned the following Error.

    “Resource at URL Contents Exceeded Maximum Size”

    Thoughts?

    Pat

    • Hi, Pat,

      Actually, I was unaware of that issue due to my testing with a limited dataset.

      Thanks for the info.

      You can try the following workaround.

      Remove unwanted rows and columns in your Sheet (published). The aim is to reduce the file size. Then try.

      If that doesn’t work, try to import a limited number of rows.

      Existing Formula.

      =IMPORTXML("URL","//a/@href")

      Play around with;

      =Array_Constrain(IMPORTXML("URL","//a/@href"),500,1)

      This formula imports 500 rows and 1 column.

      But I didn’t test any of the above workarounds.

      Thanks for your understanding.

      Best

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.