We’ll use a bunch of URLs from the Exceldemy website to show how you can extract them.
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.
- To create a new module, choose the Module option from the Insert tab.
- 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)
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.
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.
- 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.
- 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.
- 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
- How to Find and Replace Hyperlinks in Excel
- [Fix:] Hyperlink to Website Not Working in Excel
- Hyperlink in Excel Not Working
- How to Solve ‘Cannot Open the Specified File’ Error in Excel Hyperlink
- [Fixed!] Hyperlinks in Excel Not Working After Saving
- [Fixed!] Excel Hyperlink Keeps Coming Back
- [Fixed!] Excel Hyperlink Formula Not Working
- [Fixed!] Excel Hyperlink Is Not Redirecting Properly
<< Go Back To Hyperlink in Excel | Linking in Excel | Learn Excel
Get FREE Advanced Excel Exercises with Solutions!