Please Note: This article is written for users of the following Microsoft Excel versions: 2007, 2010, 2013, 2016, 2019, 2021, 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: Converting a Range of URLs to Hyperlinks.

Converting a Range of URLs to Hyperlinks

Written by Allen Wyatt (last updated April 27, 2024)

7

John has a workbook that has well over a thousand URLs in it, all in column A. These are not hyperlinks; they are straight text of individual URLs. John wants to convert the URLs to active hyperlinks, but doing the conversion individually is extremely tedious, especially for that many URLs.

One way to do the conversion is to use the HYPERLINK function. Put this formula in cell B1 and copy it down as many cells as necessary:

=IF(A1="","",HYPERLINK(IF(LEFT(A1,7)="http://","","http://")&A1))

The result is that column B will contain hyperlinks for everything in column A. The formula isn't terribly robust, as it only deals with the presence or lack of the text "http://", and you may need it to also deal with "https" addresses. It is possible to adjust the formula (i.e., making it more complex), but you may also want to consider using a macro to do the conversions.

To be effective, the macro would need to step through each cell in a selected range and, if the cell is not blank, convert the contents to a hyperlink. The following will do the trick:

Sub URL_List()
    Dim sTemp As String
    Dim sURL As String
    Dim cell As Range

    For Each cell In Selection
        If cell.Value <> "" Then
            sTemp = Left(cell.Value, 7)
            If sTemp = "http://" Or sTemp = "https:/" Then
                sURL = cell.Value
            Else
                sURL = "http://" & cell.Value
            End If
            ActiveSheet.Hyperlinks.Add Anchor:=cell, _
              Address:=sURL, TextToDisplay:=cell.Value
        End If
    Next cell
End Sub

The macro is not foolproof; it assumes that if a cell contains anything at all it is a valid URL. What it does is to check the cell contents and, if the contents aren't prefaced by the "http://" or "https:/" text, then a prefix of "http://" is added. The hyperlink is then created based on the cell contents.

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 (5825) applies to Microsoft Excel 2007, 2010, 2013, 2016, 2019, 2021, and Excel in Microsoft 365. You can find a version of this tip for the older menu interface of Excel here: Converting a Range of URLs to 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

Sticking with the Dashes

By default, dashes don't "stick" to the text that follows them. Here's one way around this normal formatting convention.

Discover More

Automatic Page Numbers across Multiple Documents

Word allows you to specify the starting page number for a document, which comes in handy if you have multiple documents ...

Discover More

Use Filenames that Sort Properly

When storing your Excel workbook, you need to specify a file name to be used for the workbook. Take a moment to consider ...

Discover More

Excel Smarts for Beginners! Featuring the friendly and trusted For Dummies style, this popular guide shows beginners how to get up and running with Excel while also helping more experienced users get comfortable with the newest features. Check out Excel 2019 For Dummies today!

More ExcelTips (ribbon)

Converting to Hyperlinks in a Shared Workbook

When you enter a URL or e-mail address in a worksheet, Excel usually converts it to a clickable hyperlink. This doesn't ...

Discover More

Extracting Hyperlink Information

In Excel, a hyperlink consists of two parts: the text displayed for the link and the target of the link. You can use a ...

Discover More

Dynamic Hyperlinks in Excel

Hyperlinks to many types of Web sites rely on passing parameters in the URL. Knowing this, you can construct a dynamic ...

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 four more than 7?

2024-10-09 10:24:33

J. Woolley

@AJnRe. my most recent comment below: On third thought, simply replace the following linen            ActiveSheet.Hyperlinks.Add Anchor:=cell, Address:=sURLnwith these linesn            On Error Resume Nextn                ActiveSheet.Hyperlinks.Add Anchor:=cell, Address:=sURLn            On Error GoTo 0nThis should work in either the Tip's version or in my first version of the macro. It skips over cell values that do not make valid http hyperlinks.


2024-10-08 16:58:55

J. Woolley

@AJnRe. my previous comment below: On second thought, replace the following linen            ActiveSheet.Hyperlinks.Add Anchor:=cell, Address:=sURLnwith these linesn            Dim n As Integern            n = InStr(Mid(sURL, InStr(sURL, "://") + 4), "/")n            If n = 0 Then n = Len(sURL)n            If InStr(Left(sURL, n), " ") + InStr(Left(sURL, n), "%") = 0 Thenn                ActiveSheet.Hyperlinks.Add Anchor:=cell, Address:=sURLn            End Ifnbecause the address part of a URL must not contain any space characters and the Hyperlinks.Add method will not accept %20 as a substitute. Spaces in the subaddress part are automatically replaced by %20. For example, consider the following cell values:nhttp://my site.com -- cannot create hyperlinknhttp://my%20site.com -- cannot create hyperlinknhttp://mysite.com/a b c/ -- hyperlink is http://mysite.com/a%20b%20c/


2024-10-08 11:05:44

J. Woolley

@AJnYou probably had leading space characters in some cells. Try this version:nnSub URL_List()n    Dim sTmp As String, sURL As String, cell As Rangen    'WARNING: This macro assumes web site (http) URLsn    For Each cell In Selectionn        sURL = Trim(cell.Value)n        If sURL <> "" Thenn            sTmp = Left(sURL, 7)n            If sTmp <> "http://" And sTmp <> "https:/" Thenn                sURL = "http://" & sURLn            End Ifn            ActiveSheet.Hyperlinks.Add Anchor:=cell, Address:=sURLn        End Ifn    Next cellnEnd Sub


2024-10-07 10:56:35

AJ

HinnFor me, running this code on a selected range, causes a debug (run-time error '1004': Application-defined or object-defined error) at this stage:nn ActiveSheet.Hyperlinks.Add Anchor:=cell, _n Address:=sURL, TextToDisplay:=cell.ValuennRegards,nnAJ


2024-04-28 14:02:53

J. Woolley

My Excel Toolbox includes the following function which is a superior substitute for Excel's HYPERLINK function:n    =SuperLink(Link_Location, [Friendly_Name], [Screen_Tip])nSuperLink is fully described in the PDF document UseSuperLink.pdf.nSee https://sites.google.com/view/MyExcelToolbox/


2024-04-28 12:31:02

J. Woolley

@Bill MultacknAssuming you are referring to Ctrl+K hyperlinks, not HYPERLINK(...) formulas, select the column of hyperlinks and run this macro:nnSub ShowHyperlinkAddress()n    Dim HL As Hyperlinkn    For Each HL In Selection.Hyperlinksn        HL.TextToDisplay = HL.Addressn    Next HLnEnd Sub


2024-04-27 09:00:09

Bill Multack

I have just the opposite problem. I have a column of hyperlinks that all have display values. I would like to strip away the TextToDisplay values and only show the hyperlink. Any suggestions?


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.