Please Note: This article is written for users of the following Microsoft Excel versions: 2007, 2010, 2013, 2016, 2019, and Excel in Microsoft 365. If you are using an earlier version (Excel 2003 or earlier), this tip may not work for you. For a version of this tip written specifically for earlier versions of Excel, click here: Extracting URLs from Hyperlinks.

Extracting URLs from Hyperlinks

Written by Allen Wyatt (last updated May 1, 2021)
This tip applies to Excel 2007, 2010, 2013, 2016, 2019, and Excel in Microsoft 365


Mezga has a series of cells that contain hyperlinks. These hyperlinks consist of words such as "click here" or "more information." In other words, each hyperlink contains display text that is different from the underlying URL that is activated when the link is clicked. Mezga would like to know if there is a way, without using a macro, to extract the underlying URL for each of these hyperlinks and place that URL into a different cell.

Without using macros, you can do this:

  1. Right-click a hyperlink. You'll see a Context menu appear.
  2. From the Context menu, choose Edit Hyperlink. Excel displays the Edit Hyperlink dialog box. (See Figure 1.)
  3. Figure 1. The Edit Hyperlink dialog box.

  4. Select and copy (Ctrl+C) the entire URL from the Address field of the dialog box.
  5. Press Esc to close the Edit Hyperlink dialog box.
  6. Paste the URL into any cell desired.

Note that this is for a single hyperlink. If you have a whole bunch of hyperlinks in a worksheet and you want to recover the URLs, you need to do this for each and every hyperlink. Obviously this can get tedious very quickly.

The cure for tedium—like them or not—is a macro. With a macro, getting at the underlying URL for a hyperlink is child's play. All the macro needs to do is pay attention to the Address property of the hyperlink. The following is an example of a macro that will find each hyperlink in a worksheet, extract each one's URL, and stick that URL in the cell directly to the right of the hyperlink.

Sub ExtractHL()
    Dim HL As Hyperlink
    For Each HL In ActiveSheet.Hyperlinks
        HL.Range.Offset(0, 1).Value = HL.Address
    Next
End Sub

Instead of a "brute force" macro, you could also create a user-defined function that would extract and return the URL for any hyperlink at which it was pointed:

Function GetURL(rng As Range) As String
    On Error Resume Next
    GetURL = rng.Hyperlinks(1).Address
End Function

In this case you can place it where you want. If you want, for example, the URL from a hyperlink in A1 to be listed in cell C25, then in cell C25 you would enter the following formula:

=GetURL(A1)

Note:

If you would like to know how to use the macros described on this page (or on any other page on the ExcelTips sites), I've prepared a special page that includes helpful information. Click here to open that special page in a new browser tab.

ExcelTips is your source for cost-effective Microsoft Excel training. This tip (9815) applies to Microsoft Excel 2007, 2010, 2013, 2016, 2019, and Excel in Microsoft 365. You can find a version of this tip for the older menu interface of Excel here: Extracting URLs from Hyperlinks.

Author Bio

Allen Wyatt

With more than 50 non-fiction books and numerous magazine articles to his credit, Allen Wyatt is an internationally recognized author. He is president of Sharon Parq Associates, a computer and publishing services company. ...

MORE FROM ALLEN

Deleting a Chart

Charts serve a purpose, and sometimes that purpose is temporary. If you want to get rid of a chart, here's how to do it.

Discover More

Printing Comments

Comments can be a boon when you want to annotate your worksheets. If you want, you can instruct Excel to print the ...

Discover More

Jumping to a Table Row

Need to jump to a particular row in a table? Word provides an easy way to jump to all sorts of things, but it doesn't ...

Discover More

Comprehensive VBA Guide Visual Basic for Applications (VBA) is the language used for writing macros in all Office programs. This complete guide shows both professionals and novices how to master VBA in order to customize the entire Office suite for their needs. Check out Mastering VBA for Office 2010 today!

More ExcelTips (ribbon)

Specifying a Browser in a Hyperlink

Excel allows you to easily add hyperlinks to a worksheet. Click on it, and the target of the link is opened in a browser ...

Discover More

Opening Sites in a Browser

You can store all sorts of information in a worksheet, including Web addresses. If you want to open those addresses in a ...

Discover More

Can't Use Hyperlinks

Before some features in Excel can function properly, you must have the correct permissions set for the user of the ...

Discover More
Subscribe

FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."

View most recent newsletter.

Comments

If you would like to add an image to your comment (not an avatar, but an image to help in making the point of your comment), include the characters [{fig}] (all 7 characters, in the sequence shown) in your comment text. You’ll be prompted to upload your image when you submit the comment. Maximum image size is 6Mpixels. Images larger than 600px wide or 1000px tall will be reduced. Up to three images may be included in a comment. All images are subject to review. Commenting privileges may be curtailed if inappropriate images are posted.

What is 1 + 1?

There are currently no comments for this tip. (Be the first to leave your comment—just use the simple form above!)


This Site

Got a version of Excel that uses the ribbon interface (Excel 2007 or later)? This site is for you! If you use an earlier version of Excel, visit our ExcelTips site focusing on the menu interface.

Newest Tips
Subscribe

FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."

(Your e-mail address is not shared with anyone, ever.)

View the most recent newsletter.