Forum Discussion
tachyglossus
Apr 06, 2020Copper Contributor
How can I extract URL from hyperlinks?
I have a worksheet where one column contains hyperlinks (like created with =HYPERLINK(link;text)). How can I create a formula extracting link urls from those hyperlinks? I've tried dozen of search qu...
esyexcel
Dec 13, 2021Copper Contributor
Extracting a URL from a hyperlink on Excel is easy!
Option 1: If you want to run this operation one time
- Open up a new workbook.
- Get into VBA (Press Alt+F11)
- Insert a new module (Insert > Module)
- Copy and Paste the Excel user defined function below
- Press F5 and click “Run”
- Get out of VBA (Press Alt+Q)
Sub ExtractHL()
Dim HL As Hyperlink
For Each HL In ActiveSheet.Hyperlinks
HL.Range.Offset(0, 1).Value = HL.Address
Next
End Sub
Option 2: If you plan to add more hyperlinks to the spreadsheet and need to store the formula on the sheet
- Open up a new workbook.
- Get into VBA (Press Alt+F11)
- Insert a new module (Insert > Module)
- Copy and Paste the Excel user defined function below
- Get out of VBA (Press Alt+Q)
- Use this syntax for this custom Excel function: =GetURL(cell,[default_value])
Function GetURL(cell As range, _
Optional default_value As Variant)
'Lists the Hyperlink Address for a Given Cell
'If cell does not contain a hyperlink, return default_value
If (cell.range("A1").Hyperlinks.Count <> 1) Then
GetURL = default_value
Else
GetURL = cell.range("A1").Hyperlinks(1).Address & "#" & cell.range("A1").Hyperlinks(1).SubAddress
End If
End Function
For more visit esyExcel
Lisa_Hochhauser
Oct 01, 2022Copper Contributor
esyexcel Thanks! a 10 second fix to something that would have otherwise taken me a few hours!