How to Extract Hyperlink from URL in Excel (3 Methods)

We’ll use a bunch of URLs from the Exceldemy website to show how you can extract them.

Extract Hyperlinks from URLs in Excel


Method 1 – Create a User-Defined Function to Extract a Hyperlink from URL in Excel

Steps:

  • From the Excel Ribbon, go to the Developer tab.
  • Click on the Visual Basic option to open the Visual Basic Editor.

Extract Hyperlinks from URLs in Excel

  • To create a new module, choose the Module option from the Insert tab.

Extract Hyperlinks from URLs in Excel

  • Copy the following code into the code editor.
Function EXTRACTHYPELINK(Rng As Range) As String
    EXTRACTHYPELINK = Rng.Hyperlinks(1).Address
End Function

We used the Hyperlinks constructor to create a custom function named EXTRACTHYPELINK that can be used as a regular function in our worksheet.

  • In our dataset, we have 5 URLs in cells B5:B9.

  • In cell C5, when we tried to type the function named EXTRACTHYPELINK, Excel provides us the user-defined function as an automatic suggestion. Press the Tab key to accept the suggestion and put B5 as the function argument.

  • Alternatively, type the full function or insert the following formula in cell C5 and press Enter.
=EXTRACTHYPERLINK(B5)

Extract Hyperlinks From URLs in Excel

We can see the extracted URL in cell C5.

  • To get the other URLs, locate the Fill Handle at the bottom-right corner of cell C5 and drag it down.

Extract Hyperlinks From URLs in Excel


Method 2 – Excel VBA Code to Get a Hyperlink from URL

We have 7 different URLs in cells B5:B11 from which we’ll extract the hyperlinks.

Steps:

  • Put the following code in the Visual Code Editor:
Sub ExtractHLinksUrls()
Dim Rng As Range
Dim SelectRange As Range
On Error Resume Next
xTitleId = "Exceldemy"
Set SelectRange = Application.Selection
Set SelectRange = Application.InputBox("Range", xTitleId, SelectRange.Address, Type:=8)
For Each Rng In SelectRange
    If Rng.Hyperlinks.Count > 0 Then
        Rng.Value = Rng.Hyperlinks.Item(1).Address
    End If
Next
End Sub
  • Press F5 to run the code. An input box opens to select the range of cells.
  • Select cells B5:B11 to fill the Range input box and then click OK.

Extract Hyperlinks from URLs in Excel

  • Here is the list of extracted hyperlinks.

Read More: How to Add Hyperlink to Another Sheet in Excel


Method 3 – Extract a Hyperlink from URL Using the Edit Hyperlink Feature in Excel

Steps:

  • Click on the cell containing the URL to be extracted. We selected cell B5.
  • Right-click and select Edit Hyperlink.

Extract Hyperlinks from URLs in Excel

  • This opens the Edit Hyperlink window. The Address input box shows the hyperlink.

  • Press Ctrl + C to copy the hyperlink and click OK to close the window.
  • Paste the copied link in the desired cell. We pasted the hyperlink associated with cell B5 in cell C5.

Extract Hyperlinks from URLs in Excel

  • Repeat the process to get all other hyperlinks one by one.

Read More: How to Edit Hyperlink in Excel 


Things to Remember

  • Although using VBA code is great to accomplish our goal. But once the code is run, we lose the history. It means we cannot undo the change anymore.
  • In case we need to change our source data from time to time, it’s better to use methods that use functions as we used in method 1. In this case, the output is dynamic with the change of the source data.

Download the Practice Workbook


Related Articles

<< Go Back To Hyperlink in Excel | Linking in Excel | Learn Excel

Get FREE Advanced Excel Exercises with Solutions!
Al Arafat Siddique
Al Arafat Siddique

Al Arafat Siddique, BSc, Naval Architecture and Marine Engineering, Bangladesh University of Engineering and Technology, has worked on the ExcelDemy project for two years. He has written over 85+ articles for ExcelDemy. Currently, he is working as a software developer. He is leading a team of six members to develop Microsoft Office Add-ins, extending Office applications to interact with office documents. Other assigned projects to his team include creating AI-based products and online conversion tools using the latest... Read Full Bio

We will be happy to hear your thoughts

Leave a reply

Advanced Excel Exercises with Solutions PDF

 

 

ExcelDemy
Logo