Forum Discussion
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 queries and carefully read everything found, but couldn't find a way.
27 Replies
- cgeisslerCopper Contributor
tachyglossus I think I found a better way using Flash Fill.
1. If Column A contains the Hyperlink text, click on the first two links (e.g. A1 and A2). Then copy/paste those two URL to notepad. You need this text to get Flash Fill to work.
2. Make a new column in excel for the URL, for example Column B
3. In B1 start typing in the URL from notepad that matches the link in Cell A1. Type the URL exactly as it appears in notepad
4. Once completed, in B2, start typing the next URL from notepad, Excel's Flash Fill will take over and suggest the URLs for all remaining cells.
No formulas, no Macros, No VBA.
- techypersonCopper Contributor
non-coding way:
- ALT + F9 (to show the hyperlinks)
- file -> options (at the bottom left of the screen) -> advanced -> print field codes instead of their values
- change the page size so the hyperlinks fit in one line (you can replace the word HYPERLINK with nothing to create more space)
- save the file as a PDF
- Copy all/paste into a new word doc.
- remove all the excess beginning and ends with 'replace' (CTRL + F -> small down arrow next to the X or magnification glass -> replace).
- Look for spaces inside the hyperlinks (they might slip in) or links that split into two lines
- SergeiBaklanDiamond Contributor
As variant
=LET( range, A1:A2, str, FORMULATEXT( range ), start, FIND( """", str )+1, end, FIND( """", str, start ), MID( str, start, end-start ) )
- anupambit1797Iron Contributor
HiSergeiBaklan , I tried to use this LET function, to extract the URL, but getting #NA, can you please share a sample spreadsheet with this function used?
Thanks in Advance,
Br,
Anupam
- LanserJCopper Contributor
the #N/A is caused by FormulaText function if the Hyperlink is set by the Edit Hyperlink editor then there is no formula to extract the text from.
- TownTasksCopper Contributor
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 https://towntasks.com- happydz1815Copper Contributor
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.
- esyexcelCopper 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 SubOption 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 FunctionFor more visit https://esyexcel.com/
- Lisa_HochhauserCopper Contributor
esyexcel Thanks! a 10 second fix to something that would have otherwise taken me a few hours!
- Juliano-PetrukioBronze ContributorIf 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 - datta9381Copper Contributor
- 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 Subhttps://my-notebook-online-2021.blogspot.com/2021/08/how-to-extract-hyperlink-in-excel.html
- agrawalr1Copper Contributor
WORKS RIGHT AWAY; ALL WE HAVE TO DO IS ADD A COLUMN RIGHT OF THE HYPERLINK.
ATEN USE TEXT TO COLUMN OPTION SEPEARTE AND TAG
- OscarIsMyDogsNameCopper Contributor
agrawalr1 can you provide the specific syntax for that? E. G. If the hyperlink is in A1, what is the formula you would type in B1?
- donwojtoCopper Contributor
amazing work. Thank you!
- AdamLongCopper ContributorThank you. The VBA code worked quite well.
- NikolinoDEGold Contributor
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: = 😎
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.
- nicoatridgeCopper Contributor
NikolinoDE Really great tip - although be warned that if you cut and paste the code a couple of spurious spaces appear in the line that should be copied as:
Rng.Value = Rng.Hyperlinks.Item(1).Address
- jkaufmanCopper Contributor
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.
- NinjaIceCopper Contributor
Thanks for this. I was able to improve your method significantly.
https://www.reddit.com/r/excel/comments/tvjrz3/excel_extract_urls_from_hyperlinks/
Hello, you can follow the steps in the link below
https://howtouseexcel.net/how-to-extract-a-url-from-a-hyperlink-on-excel
- NAGDTCopper Contributor
https://howtouseexcel.net/how-to-extract-a-url-from-a-hyperlink-on-excel
is broken and generates the message:
Error establishing a database connection
- OscarIsMyDogsNameCopper Contributor
Abiola1 The link you provided no longer seems to work.
- JMB17Bronze Contributor