How can I extract URL from hyperlinks?

Copper Contributor

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 queries and carefully read everything found, but couldn't find a way.

23 Replies

@tachyglossus 

Hello,

 

  1. Right-click a hyperlink.
  2. From the Context menu, choose Edit Hyperlink. Excel displays the Edit Hyperlink dialog box.
  3. Select and copy (Ctrl+C) the entire URL from the Address field of the dialog box.
  4. Press Esc to close the Edit Hyperlink dialog box.
  5. Paste the URL into any cell desired.

@Abiola1 The link you provided no longer seems to work.

@tachyglossus

 

Here's another non-scripting method I've used for years.

 

1. Copy your column containing the links and paste it into a Word document.

2. Save your Word document as "Web Page (*.htm, *.html)".

3. Right-click on the .htm file and open in Notepad (to view the html source code).

4. Find the rows of code that contain your hyperlinks and copy them, then paste into a Word document. 

5. Use find and replace to delete unwanted code until you are left with only the hyperlinks. 

6. Create a new column next to your original column in your spreadsheet and paste them in. 

7. Check the beginning and end to make certain the URLs are pasted back into the corresponding rows.

@tachyglossus 

 

Extract actual addresses from hyperlinks with VBA code

Press on the heading to get more possibilities and options.

 

Hold down the ALT + F11 keys to open the Microsoft Visual Basic for Applications window.

  Click Insert> Module and paste the following code into the module window.

 

Sub Extracthyperlinks ()

'Updateby Extendoffice

Dim Rng As Range

Dim WorkRng As Range

On Error Resume Next

xTitleId = "KutoolsforExcel"

Set WorkRng = Application.Selection

Set WorkRng = Application.InputBox ("Range", xTitleId, WorkRng.Address, Type: = 8)

For Each Rng In WorkRng

     If Rng.Hyperlinks.Count> 0 Then

         Rng.Value = Rng.Hyperlinks.Item (1) .Address

     End If

Next

End Sub

 

Then press F5 when you press the key to run the code, it will bring up a dialog box for you to choose the hyperlinks that you want to extract the actual addresses from.

Then click OK and the selected cell contents will be converted to the real hyperlink addresses in the original range.

 

 

  1. Open up a new workbook.
  2. Get into VBA (Press Alt+F11)
  3. Insert a new module (Insert > Module)
  4. Copy and Paste the Excel user defined function below
  5. Press F5 and click “Run”
  6. 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

@tachyglossus 

For More Info

@datta9381  Thank you, that saved me some time. I just had to add the SubAddress property to get the full address of my links instead of just the domain piece:

 

HL.Range.Offset(0, 1).value = HL.Address & HL.SubAddress

 

If you are using HYPERLINK formula, even its a complex formula to generate your link address you just need copy the same formula and instead of HYPERLINK(link;text)) you can delete the formula where will remain only the link
from
=HYPERLINK(A1;"Friendly Name"
to
=A1

@tachyglossus 

 

Extracting a URL from a hyperlink on Excel is easy!

Option 1: If you want to run this operation one time

  1. Open up a new workbook.
  2. Get into VBA (Press Alt+F11)
  3. Insert a new module (Insert > Module)
  4. Copy and Paste the Excel user defined function below
  5. Press F5 and click “Run”
  6. 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

  1. Open up a new workbook.
  2. Get into VBA (Press Alt+F11)
  3. Insert a new module (Insert > Module)
  4. Copy and Paste the Excel user defined function below
  5. Get out of VBA (Press Alt+Q)
  6. 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

Without using macros, you can follow below steps.

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
3. Select and copy the entire URL from the Address field of the dialog box.
4. Press Escape to close the Edit Hyperlink dialog box.
5. Paste the URL into any cell desired.


With Macro

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


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



=GetURL(A1)

Hopefully you will get it solved, Follow to learn more TownTasks

@tachyglossus 

As variant

=LET(
    range,    A1:A2,
    str,      FORMULATEXT( range ),
    start,    FIND( """", str )+1,
    end,      FIND( """", str, start ),
    MID( str, start, end-start )  )

@tachyglossus 

non-coding way:

  1. ALT + F9 (to show the hyperlinks)
  2. file -> options (at the bottom left of the screen) -> advanced -> print field codes instead of their values
  3. change the page size so the hyperlinks fit in one line (you can replace the word HYPERLINK with nothing to create more space)
  4. save the file as a PDF
  5. Copy all/paste into a new word doc.
  6. remove all the excess beginning and ends with 'replace' (CTRL + F -> small down arrow next to the X or magnification glass -> replace).
  7. Look for spaces inside the hyperlinks (they might slip in) or links that split into two lines

Thanks for this. I was able to improve your method significantly.

Excel Extract URLs from Hyperlinks : excel (reddit.com)

@TownTasks the hyperlinks are not clickable unless I click twice on the cell. Could you give any hint or trick to fix this thing, please!

P.S: I tried both macro and GetURL function.

 

Created an account to like this, you saved me hours of work with this. Thank you SO much!
Thank you. The VBA code worked quite well.

@esyexcel Thanks!  a 10 second fix to something that would have otherwise taken me a few hours!

@datta9381 

amazing work. Thank you!