Get the hyperlink in excel

Excel for Microsoft 365 Excel for Microsoft 365 for Mac Excel for the web Excel 2021 Excel 2021 for Mac Excel 2019 Excel 2019 for Mac Excel 2016 Excel 2016 for Mac Excel 2013 Excel 2010 Excel 2007 Excel for Mac 2011 Excel Starter 2010 More…Less

This article describes the formula syntax and usage of the HYPERLINK function in Microsoft Excel.

Description

The HYPERLINK function creates a shortcut that jumps to another location in the current workbook, or opens a document stored on a network server, an intranet, or the Internet. When you click a cell that contains a HYPERLINK function, Excel jumps to the location listed, or opens the document you specified.

Syntax

HYPERLINK(link_location, [friendly_name])

The HYPERLINK function syntax has the following arguments:

  • Link_location    Required. The path and file name to the document to be opened. Link_location can refer to a place in a document — such as a specific cell or named range in an Excel worksheet or workbook, or to a bookmark in a Microsoft Word document. The path can be to a file that is stored on a hard disk drive. The path can also be a universal naming convention (UNC) path on a server (in Microsoft Excel for Windows) or a Uniform Resource Locator (URL) path on the Internet or an intranet.

    Note   Excel for the web the HYPERLINK function is valid for web addresses (URLs) only. Link_location can be a text string enclosed in quotation marks or a reference to a cell that contains the link as a text string.

    If the jump specified in link_location does not exist or cannot be navigated, an error appears when you click the cell.

  • Friendly_name    Optional. The jump text or numeric value that is displayed in the cell. Friendly_name is displayed in blue and is underlined. If friendly_name is omitted, the cell displays the link_location as the jump text.

    Friendly_name can be a value, a text string, a name, or a cell that contains the jump text or value.

    If friendly_name returns an error value (for example, #VALUE!), the cell displays the error instead of the jump text.

Remark

In the Excel desktop application, to select a cell that contains a hyperlink without jumping to the hyperlink destination, click the cell and hold the mouse button until the pointer becomes a cross Excel selection cursor, then release the mouse button. In Excel for the web, select a cell by clicking it when the pointer is an arrow; jump to the hyperlink destination by clicking when the pointer is a pointing hand.

Examples

Example

Result

=HYPERLINK(«http://example.microsoft.com/report/budget report.xlsx», «Click for report»)

Opens a workbook saved at http://example.microsoft.com/report. The cell displays «Click for report» as its jump text.

=HYPERLINK(«[http://example.microsoft.com/report/budget report.xlsx]Annual!F10», D1)

Creates a hyperlink to cell F10 on the Annual worksheet in the workbook saved at http://example.microsoft.com/report. The cell on the worksheet that contains the hyperlink displays the contents of cell D1 as its jump text.

=HYPERLINK(«[http://example.microsoft.com/report/budget report.xlsx]’First Quarter’!DeptTotal», «Click to see First Quarter Department Total»)

Creates a hyperlink to the range named DeptTotal on the First Quarter worksheet in the workbook saved at http://example.microsoft.com/report. The cell on the worksheet that contains the hyperlink displays «Click to see First Quarter Department Total» as its jump text.

=HYPERLINK(«http://example.microsoft.com/Annual Report.docx]QrtlyProfits», «Quarterly Profit Report»)

To create a hyperlink to a specific location in a Word file, you use a bookmark to define the location you want to jump to in the file. This example creates a hyperlink to the bookmark QrtlyProfits in the file Annual Report.doc saved at http://example.microsoft.com.

=HYPERLINK(«\FINANCEStatements1stqtr.xlsx», D5)

Displays the contents of cell D5 as the jump text in the cell and opens the workbook saved on the FINANCE server in the Statements share. This example uses a UNC path.

=HYPERLINK(«D:FINANCE1stqtr.xlsx», H10)

Opens the workbook 1stqtr.xlsx that is stored in the Finance directory on drive D, and displays the numeric value that is stored in cell H10.

=HYPERLINK(«[C:My DocumentsMybook.xlsx]Totals»)

Creates a hyperlink to the Totals area in another (external) workbook, Mybook.xlsx.

=HYPERLINK(«[Book1.xlsx]Sheet1!A10″,»Go to Sheet1 > A10»)

To jump to a different location in the current worksheet, include both the workbook name, and worksheet name like this, where Sheet1 is the current worksheet.

=HYPERLINK(«[Book1.xlsx]January!A10″,»Go to January > A10»)

To jump to a different location in the current worksheet, include both the workbook name, and worksheet name like this, where January is another worksheet in the workbook.

=HYPERLINK(CELL(«address»,January!A1),»Go to January > A1″)

To jump to a different location in the current worksheet without using the fully qualified worksheet reference ([Book1.xlsx]), you can use this, where CELL(«address») returns the current workbook name.

=HYPERLINK($Z$1)

To quickly update all formulas in a worksheet that use a HYPERLINK function with the same arguments, you can place the link target in another cell on the same or another worksheet, and then use an absolute reference to that cell as the link_location in the HYPERLINK formulas. Changes that you make to the link target are immediately reflected in the HYPERLINK formulas.

Need more help?

Sometimes, you copy webpages. Or just a link. Or you receive an Excel sheet with links in it. In such case, you often want to extract the hyperlink addresses from the cells. There are basically just three options for extracting the hyperlink address from an Excel cell. 

Method 1: Extracting the link addresses manually

VBA, Hyperlink Address, link, address, return, excel, hyperlink

The bad news first: There is no built-in way in Excel to read out a hyperlink, for example with a formula. So the first approach would be typing the hyperlink addresses manually. 

  1. Right click on the cell containing the hyperlink address.
  2. Click on ‘Edit Hyperlink…’.
  3. Copy the link from the address field and paste it wherever you need it.

This method might work for just a couple of links. But if you got more hyperlinks to extract, you might continue with the second or third option.Also, you could try clicking on the link address. That way, a internet browser window opens and you can copy the link address from the address bar.

Method 2: Using VBA for returning the hyperlink address

As we have the bad news covered with the first option, there is also good news: With a short VBA macro it’s still possible to extract the link addresses.

The following macro defines a new excel function. You can use it by typing “=PROFEXHyperlinkAddress(A1)” into your cell (instead of A1 you can of course use any cell reference). After pressing enter, the hyperlink of cell A1 will be displayed. If there is no hyperlink in a cell, nothing will be shown.

Just start by opening the VBA window (Ribbon “Developer”–>”Editor”). Then add a new module (right click in the Project Explorer –> Insert –> Module) and paste the following code into the new macro. If you need more help with VBA macros, please refer to this article.

Function PROFEXHyperlinkAddress(Zelle As Range)
'This function returns a hyperlink address from a cell, for example from a text, copied from the internet

'The cell with the actual hyperlink will be saved in "Zelle"

Dim Link As String
'The link will be saved in the variable "Link"

Application.Volatile
'With "Application.Volatile" you can make sure, that the function will be recalculated once the worksheet is recalculated
'for example, when you press F9 (Windows) or press enter in a cell

If Zelle.Hyperlinks.count Then
'Return the address if there is at least one cell selected
Link = Zelle.Hyperlinks(1).Address

'Return the link address of the first item of the array (in case there are more than one cell selected)

End If

PROFEXHyperlinkAddress = Link
'Return the link

End Function

Method 3: Inserting the link address with ‘Professor Excel Tools’

hyperlink, address, return, get, read, excel, cell, professor
Comfortably get the hyperlink address from Excel cells with Professor Excel Tools

The third option doesn’t involve any VBA. Just download the Excel add-in Professor Excel Tools from below (no sign-up, just activate it within Excel). For getting the link address type =PROFEXHyperlinkAddress(A1) into a cell. Instead of A1 you refer to the cell containing the link.


Professor Excel Tools Box

This function is included in our Excel Add-In ‘Professor Excel Tools’

(No sign-up, download starts directly)


Henrik Schiffner is a freelance business consultant and software developer. He lives and works in Hamburg, Germany. Besides being an Excel enthusiast he loves photography and sports.

Do you want to know how to extract the URL from a hyperlink in Microsoft Excel?

This post is going to show you all the ways you can get the URL from a hyperlink in Microsoft Excel!

A hyperlink is a link that allows users to navigate to a web page or document. Hyperlink cells typically contain a URL, which is the address of the linked page or document, and anchor text, which is the text that appears on the screen and is clicked by the user.

When the hyperlink uses anchor text, the actual URL isn’t easily accessible in Excel but you may need this data for other purposes.

Follow this easy step-by-step guide on how to extract the URL from a hyperlink in Microsoft Excel.

Extract the Hyperlink URL with a Click

This is the most obvious method to get the URL from any hyperlink.

When you click on the hyperlink, Excel will launch your internet browser and take you to the website URL.

You can then copy and paste the URL from the browser address bar back into Excel.

Highlight the URL and press Ctrl + C to copy, then go back to Excel and press Ctrl + V to paste the URL into a new cell.

Unfortunately, this is a very manual approach that involves switching back and forth between two applications. There are definitely easier methods!

Extract the Hyperlink URL from the Insert Menu

A slightly easier way to get the URL from your hyperlinks is through the Link command found in the Insert menu.

Follow these steps to extract the URL from the Link command.

  1. Select the cell that contains your hyperlink.
  2. Go to the Insert tab in the ribbon.
  3. Click on the Link command found in the Links section.

This will open the Edit Hyperlink menu which contains both the anchor text and the URL address data.

  1. Highlight the URL from the Address input in the Edit Hyperlink menu and press Ctrl + C to copy.
  2. Press Esc on your keyboard or press the Cancel button to close the Edit Hyperlink menu.
  3. Select a new cell and press Ctrl + V to paste the URL into Excel.

You now have the URL from the hyperlink!

Extract the Hyperlink URL with a Right Click

You can also access the Edit Hyperlink menu with a right-click to avoid using the ribbon commands.

  1. Select the cell from which you want to extract the URL.
  2. Right click and choose Edit Hyperlink from the options.

This will open the Edit Hyperlink menu and you can copy and paste the URL from the Address as before.

Extract the Hyperlink URL with a Keyboard Shortcut

Using a keyboard shortcut to open the Edit Hyperlink menu is slightly quicker than the previous methods for getting the URL.

This is my favorite method when I only need to extract a couple of URLs from their hyperlinked cells.

Select the cell containing the hyperlink and press Ctrl + K to open the Edit Hyperlink menu.

This will open the Edit Hyperlink menu and you can copy and paste the URL from the Address just like before.

Extract the Hyperlink URL with VBA

If you work with hyperlinks in Excel, you know that it can be a tedious task to extract the URL from each hyperlink.

To save yourself time and effort, you can use VBA to automate the process.

With just a few lines of code, you can extract the URL from multiple hyperlinks in Excel.

Not only does this save you time, but it also ensures the results are accurate as manual processes tend to lead to errors.

Follow these steps to create a VBA macro to extract the URL from your hyperlinks.

  1. Press Alt + F11 to open the Visual Basic Editor (VBE).
  2. Click on the Insert tab of the VBE.
  3. Select Module from the options.
Sub ExtractURL()

Dim rng As Range

For Each rng In Selection
    rng.Offset(0, 1).Value = rng.Hyperlinks(1).Address
Next rng
End Sub
  1. Paste the above VBA code into the code window.

The code will loop through all of the hyperlinks in the selected range and extract the URL from each into the adjacent cell.

Now you can extract URL’s from multiple hyperlinks!

Follow these steps to extract multiple URL’s using the VBA macro.

  1. Select the range of cell from which to extract the URL.
  2. Press Alt + F8 to open the Macro dialog menu to select and run the macro.
  3. Select the ExtractURL macro.
  4. Press the Run button.

The code will run and place the URL in the adjacent cell!

Just make sure the adjacent cells don’t already contain any data or formulas as the code will overwrite anything in the cells directly to the right.

Extract the Hyperlink URL with a Custom Function

Another way you can leverage VBA to extract the URL is through a custom function.

This will allow you to get a dynamic solution, so if the hyperlinks change, the extracted URL will also update accordingly.

Add the above code into the VBE.

Function GetURL(cell As Range)
    GetURL = cell.Hyperlinks(1).Address
End Function

This code will create a custom function that returns the URL from a hyperlink. This custom function can then be used in your worksheet just like any other function.

=GetURL(B2)

Insert the above formula into your worksheet and it will return the URL from the referenced hyperlink.

Extract the Hyperlink URL with Office Scripts

VBA isn’t the only way to automate your work in Excel!

You can also use Office Scripts. It’s a TypeScript based language available in business plans of Microsoft 365 with Excel Online.

Follow these steps to create an Office Script that extracts the URL from your hyperlinks.

  1. Open your workbook in Excel Online.
  2. Go to the Automate tab in the ribbon.
  3. Click on the New Script command.

This will open the code editor on the right hand side.

function main(workbook: ExcelScript.Workbook) {

	//Create a range object from selected range
	let selectedRange = workbook.getSelectedRange();
	//Create an array with the values in the selected range
	let selectedValues = selectedRange.getValues();
	//Get dimensions of selected range
	let rowHeight = selectedRange.getRowCount();
	let colWidth = selectedRange.getColumnCount();

	//Loop through each item in the selected range
	for (let i = 0; i < rowHeight; i++) {
		for (let j = 0; j < colWidth; j++) {	
			let currHyperlink = selectedRange.getCell(i, j).getHyperlink().address;
			selectedRange.getOffsetRange(0, colWidth).getCell(i, j).setValue(currHyperlink);
		};
	};
};
  1. Paste in the above code in the Code Editor.

  1. Rename the script to Extract URL.
  2. Click the Save script button.

Now you will be able to extract the URL’s from any range of hyperlinked cells.

  1. Select the range of cells containing the hyperlinks from which you want to extract the URL.
  2. Press the Run button in the Code Editor.

This Office Script will loop through the selected range and place the URL from the hyperlink into the adjacent cell.

Conclusions

If you work with hyperlinks in Excel, you may sometimes need to extract the URL from those hyperlinks.

There are many different ways to extract the URL from a hyperlink in Microsoft Excel. The most straightforward way is to either click the link and get the URL in the browser or use the Edit Hyperlinks menu.

This is ok when you only need to get the URL from a few hyperlinks and it’s an activity you won’t be doing frequently.

Otherwise, you will need to automate the process to avoid the tedious work involved!

Thankfully, you can automate URL extraction with VBA or Office Scripts in order to get URL’s from multiple hyperlinks.

Extracting the URL from a hyperlink in Excel is a quick and easy process, and the VBA or Office Script solutions will save you tons of time and effort when working with a lot of hyperlink data.

Give it a try next time you need to extract a URL from a hyperlink in Excel! Let me know in the comments section below how it goes!

About the Author

John MacDougall

John is a Microsoft MVP and qualified actuary with over 15 years of experience. He has worked in a variety of industries, including insurance, ad tech, and most recently Power Platform consulting. He is a keen problem solver and has a passion for using technology to make businesses more efficient.

Excel allows having hyperlinks in cells which you can use to directly go to that URL.

For example, below is a list where I have company names which are hyperlinked to the company website’s URL. When you click on the cell, it will automatically open your default browser (Chrome in my case) and go to that URL.

There are many things you can do with hyperlinks in Excel (such as a link to an external website, link to another sheet/workbook, link to a folder, link to an email, etc.).

In this article, I will cover all you need to know to work with hyperlinks in Excel (including some useful tips and examples).

How to Insert Hyperlinks in Excel

There are many different ways to create hyperlinks in Excel:

  • Manually type the URL (or copy paste)
  • Using the HYPERLINK function
  • Using the Insert Hyperlink dialog box

Let’s learn about each of these methods.

Manually Type the URL

When you manually enter a URL in a cell in Excel, or copy and paste it in the cell, Excel automatically converts it into a hyperlink.

Below are the steps that will change a simple URL into a hyperlink:

  1. Select a cell in which you want to get the hyperlink
  2. Press F2 to get into the edit mode (or double click on the cell).
  3. Type the URL and press enter. For example, if I type the URL – https://trumpexcel.com in a cell and hit enter, it will create a hyperlink to it.

URL gets converted to a hypoerlink when entered

Note that you need to add http or https for those URLs where there is no www in it. In case there is www as the prefix, it would create the hyperlink even if you don’t add the http/https.

Similarly, when you copy a URL from the web (or some other document/file) and paste it in a cell in Excel, it will automatically be hyperlinked.

Insert Using the Dialog Box

If you want the text in the cell to be something else other than the URL and want it to link to a specific URL, you can use the insert hyperlink option in Excel.

Below are the steps to enter the hyperlink in a cell using the Insert Hyperlink dialog box:

  1. Select the cell in which you want the hyperlink
  2. Enter the text that you want to be hyperlinked. In this case, I am using the text ‘Sumit’s Blog’
  3. Click the Insert tab. Insert Tab in the Ribbon in Excel
  4. Click the links button. This will open the Insert Hyperlink dialog box (You can also use the keyboard shortcut – Control + K).Click on the Link option
  5. In the Insert Hyperlink dialog box, enter the URL in the Address field.
  6. Press the OK button.

Insert Hyperlink Dialog box

This will insert the hyperlink the cell while the text remains the same.

Sumit's Blog hyperlinked to the blog URL

There are many more things you can do with the ‘Insert Hyperlink’ dialog box (such as create a hyperlink to another worksheet in the same workbook, create a link to a document/folder, create a link to an email address, etc.). These are all covered later in this tutorial.

Insert Using the HYPERLINK Function

Another way to insert a link in Excel can be by using the HYPERLINK Function.

Below is the syntax:

HYPERLINK(link_location, [friendly_name])
  • link_location: This can be the URL of a web-page, a path to a folder or a file in the hard disk, place in a document (such as a specific cell or named range in an Excel worksheet or workbook).
  • [friendly_name]: This is an optional argument. This is the text that you want in the cell that has the hyperlink. In case you omit this argument, it will use the link_location text string as the friendly name.

Below is an example where I have the name of companies in one column and their website URL in another column.

Hyperlink Function - Dataset

Below is the HYPERLINK function to get the result where the text is the company name and it links to the company website.

Hyperlink Formula to get the result

In the examples so far, we have seen how to create hyperlinks to websites.

But you can also create hyperlinks to worksheets in the same workbook, other workbooks, and files and folders on your hard disk.

Let’s see how it can be done.

Create a Hyperlink to a Worksheet in the Same Workbook

Below are the steps to create a hyperlink to Sheet2 in the same workbook:

  1. Select the cell in which you want the link
  2. Enter the text that you want to be hyperlinked. In this example, I have used the text ‘Link to Sheet2’.
  3. Click the Insert tab.
  4. Click the links button. This will open the Insert Hyperlink dialog box (You can also use the keyboard shortcut – Control + K).
  5. In the Insert Hyperlink dialog box, select ‘Place in This Document’ option in the left pane.Select Place in This Document in the Insert Hyperlink Dialog box
  6. Enter the cell which you want to hyperlink (I am going with the default A1).Enter the cell to which you want to link
  7. Select the sheet that you want to hyperlink (Sheet2 in this case) Select the sheet to which you want to link
  8. Click OK.

Note: You can also use the same method to create a hyperlink to any cell in the same workbook. For example, if you want to link to a far off cell (say K100), you can do that by using this cell reference in step 6 and selecting the existing sheet in step 7.

You can also use the same method to link to a defined name (named cell or named range). If you have any named ranges (named cells) in the workbook, these would be listed in under the ‘Defined Names’ category in the ‘Insert Hyperlink’ dialog box.

Apart from the dialog box, there is also a function in Excel that allows you to create hyperlinks.

So instead of using the dialog box, you can instead use the HYPERLINK formula to create a link to a cell in another worksheet.

The below formula will do this:

=HYPERLINK("#"&"Sheet2!A1","Link to Sheet2")

Below is how this formula works:

  • “#” would tell the formula to refer to the same workbook.
  • “Sheet2!A1” tells the formula the cell that should be linked to in the same workbook
  • “Link to Sheet2” is the text that appears in the cell.

Create a Hyperlink to a File (in the same or different folders)

You can also use the same method to create hyperlinks to other Excel (and non-Excel) files that are in the same folder or are in other folders.

For example, if you want to open a file with the Test.xlsx which is in the same folder as your current file, you can use the below steps:

  1. Select the cell in which you want the hyperlink
  2. Click the Insert tab.
  3. Click the links button. This will open the Insert Hyperlink dialog box (You can also use the keyboard shortcut – Control + K).
  4. In the Insert Hyperlink dialog box, select ‘Existing File or Webpage’ option in the left pane.
  5. Select ‘Current folder’ in the Look in options
  6. Select the file for which you want to create the hyperlink. Note that you can link to any file type (Excel as well as non-Excel files)Link to a file in the current folder
  7. [Optional] Change the Text to Display name if you want to.
  8. Click OK.

In case you want to link to a file which is not in the same folder, you can Browse the file and then select it. To Browse the file, click on the folder icon in the Insert Hyperlink dialog box (as shown below).

Browse files or folder to link

You can also do this using the HYPERLINK function.

The below formula will create a hyperlink that links to a file in the same folder as the current file:

=HYPERLINK("Test.xlsx","Test File")

In case the file is not in the same folder, you can copy the address of the file and use it as the link_location.

Create a Hyperlink to a Folder

This one also follows the same methodology.

Below are the steps to create a hyperlink to a folder:

  1. Copy the folder address for which you want to create the hyperlink
  2. Select the cell in which you want the hyperlink
  3. Click the Insert tab.
  4. Click the links button. This will open the Insert Hyperlink dialog box (You can also use the keyboard shortcut – Control + K).
  5. In the Insert Hyperlink dialog box, paste folder addressEnter the address of the folder to create a link to it
  6. Click OK.

You can also use the HYPERLINK function to create a hyperlink that points to a folder.

For example, the below formula will create a hyperlink to a folder named TEST on the desktop and as soon as you click on the cell with this formula, it will open this folder.

=HYPERLINK("C:UserssumitDesktopTest","Test Folder")

To use this formula, you will have to change the address of the folder to the one you want to link to.

Create Hyperlink to an Email Address

You can also have hyperlinks which open your default email client (such as Outlook) and have the recipients email and the subject line already filled in the send field.

Below are the steps to create an email hyperlink:

  1. Select the cell in which you want the hyperlink
  2. Click the Insert tab.
  3. Click the links button. This will open the Insert Hyperlink dialog box (You can also use the keyboard shortcut – Control + K).
  4. In the insert dialog box, click on ‘E-mail Address’ in the ‘Link to’ options
  5. Enter the E-mail address and the Subject lineCreate link to Email address with subject line
  6. [Optional] Enter the text you want to be displayed in the cell.
  7. Click OK.

Now when you click on the cell which has the hyperlink, it will open your default email client with the email and subject line pre-filled.

You can also do this using the HYPERLINK function.

The below formula will open the default email client and have one email address already pre-filled.

=HYPERLINK("mailto:abc@trumpexcel.com","Send Email")

Note that you need to use mailto: before the email address in the formula. This tells the HYPERLINK function to open the default email client and use the email address that follows.

In case you want to have the subject line as well, you can use the below formula:

=HYPERLINK("mailto:abc@trumpexcel.com,?cc=&bcc=&subject=Excel is Awesome","Generate Email")

In the above formula, I have kept the cc and bcc fields as empty, but you can also these emails if needed.

Here is a detailed guide on how to send emails using the HYPERLINK function.

Remove Hyperlinks

If you only have a few hyperlinks, you can remove these manually, but if you have a lot, you can use a VBA Macro to do this.

Manually Remove Hyperlinks

Below are the steps to remove hyperlinks manually:

  1. Select the data from which you want to remove hyperlinks.
  2. Right-click on any of the selected cell.
  3. Click on the ‘Remove Hyperlink’ option.Select Remove Hyperlinks option from the right-click menu

The above steps would instantly remove hyperlinks from the selected cells.

In case you want to remove hyperlinks from the entire worksheet, select all the cells and then follow the above steps.

Remove Hyperlinks Using VBA

Below is the VBA code that will remove the hyperlinks from the selected cells:

Sub RemoveAllHyperlinks()
'Code by Sumit Bansal @ trumpexcel.com
Selection.Hyperlinks.Delete
End Sub

If you want to remove all the hyperlinks in the worksheet, you can use the below code:

Sub RemoveAllHyperlinks()
'Code by Sumit Bansal @ trumpexcel.com
ActiveSheet.Hyperlinks.Delete
End Sub

Note that this code will not remove the hyperlinks created using the HYPERLINK function.

You need to add this VBA code in the regular module in the VB Editor.

If you need to remove hyperlinks quite often, you can use the above VBA codes, save it in the Personal Macro Workbook, and add it to your Quick Access Toolbar. This will allow you to remove hyperlinks with a single click and it will be available in all the workbooks on your system.

Here is a detailed guide on how to remove hyperlinks in Excel.

Prevent Excel from Creating Hyperlinks Automatically

For some people, it’s a great feature that Excel automatically converts a URL text to a hyperlink when entered in a cell.

And for some people, it’s an irritation.

If you’re in the latter category, let me show you a way to prevent Excel from automatically creating URLs into hyperlinks.

The reason this happens as there is a setting in Excel that automatically converts ‘Internet and network paths’ into hyperlinks.

Here are the steps to disable this setting in Excel:

  1. Click the File tab.
  2. Click on Options.Click on Options
  3. In the Excel Options dialog box, click on ‘Proofing’ in the left pane.Proofing option in the left pane
  4. Click on the AutoCorrect Options button.Click on the Autocorrect Option
  5. In the AutoCorrect dialog box, select the ‘AutoFormat As You Type’ tab.Select Autoformat as you type tab
  6. Uncheck the option – ‘Internet and network paths with hyperlinks’Uncheck Internet and Network Paths with hyperlinks
  7. Click OK.
  8. Close the Excel Options dialog box.

If you’ve completed the following steps, Excel would not automatically turn URLs, email address, and network paths into hyperlinks.

Note that this change is applied to the entire Excel application, and would be applied to all the workbooks that you work with.

Extract Hyperlink URLs (using VBA)

There is no function in Excel that can extract the hyperlink address from a cell.

However, this can be done using the power of VBA.

For example, suppose you have a dataset (as shown below) and you want to extract the hyperlink URL in the adjacent cell.

Extract Hyperlink from the dataset in Excel

Let me show you two techniques to extract the hyperlinks from the text in Excel.

Extract Hyperlink in the Adjacent Column

If you want to extract all the hyperlink URLs in one go in an adjacent column, you can so that using the below code:

Sub ExtractHyperLinks()
Dim HypLnk As Hyperlink
For Each HypLnk In Selection.Hyperlinks
    HypLnk.Range.Offset(0, 1).Value = HypLnk.Address
Next HypLnk
End Sub

The above code goes through all the cells in the selection (using the FOR NEXT loop) and extracts the URLs in the adjacent cell.

In case you want to get the hyperlinks in the entire worksheet, you can use the below code:

Sub ExtractHyperLinks()
On Error Resume Next
Dim HypLnk As Hyperlink
For Each HypLnk In ActiveSheet.Hyperlinks
    HypLnk.Range.Offset(0, 1).Value = HypLnk.Address
Next HypLnk
End Sub

Note that the above codes wouldn’t work for hyperlinks created using the HYPERLINK function.

Extract Hyperlink Using a Formula (created with VBA)

The above code works well when you want to get the hyperlinks from a dataset in one go.

But if you have a list of hyperlinks that keeps expanding, you can create a User Defined Function/formula in VBA.

This will allow you to quickly use the cell as the input argument and it will return the hyperlink address in that cell.

Below is the code that will create a UDF for getting the hyperlinks:

Function GetHLink(rng As Range) As String
    If rng(1).Hyperlinks.Count <> 1 Then
        GetHLink = ""
    Else
        GetHLink = rng.Hyperlinks(1).Address
    End If
End Function

Note that this wouldn’t work with Hyperlinks created using the HYPERLINK function.

Also, in case you select a range of cells (instead of a single cell), this formula will return the hyperlink in the first cell only.

Find Hyperlinks with Specific Text

If you’re working with a huge dataset that has a lot of hyperlinks in it, it could be a challenge when you want to find the ones that have a specific text in it.

For example, suppose I have a dataset as shown below and I want to find all the cells with hyperlinks that have the text 2019 in it and change it to 2020.

Find and Replace Hyperlink Text - dataset

And no.. doing this manually is not an option.

You can do that using a wonderful feature in Excel – Find and Replace.

With this, you can quickly find and select all the cells that have a hyperlink and then change the text 2019 with 2020.

Below are the steps to select all the cells with a hyperlink and the text 2019:

  1. Select the range in which you want to find the cells with hyperlinks with 2019. In case you want to find in the entire worksheet, select the entire worksheet (click on the small triangle at the top left).
  2. Click the Home tab.Click the home tab
  3. In the Editing group, click on Find and SelectFind and Select in Excel
  4. In the drop-down, click on Replace. This will open the Find and Replace dialog box.Replace Option in Excel
  5. In the Find and Replace dialog box, click on the Options button.This will show more options in the dialog box. Click on the Options button in Find and Replace
  6. In the ‘Find What’ options, click on the little downward pointing arrow in the Format button (as shown below). Click the downward pointing arrow
  7.  Click on the ‘Choose Format From Cell’. This will turn your cursor into a plus icon with a format picker icon.Select Choose format from cell
  8. Select any cell which has a hyperlink in it. You will notice that the Format gets visible in the box on the left of the Format button. This indicates that the format of the cell you selected has been picked up.Selecting a cell with hyperlink will change the preview
  9. Enter 2019 in the ‘Find What’ field and 2020 in the ‘Replace with’ field.Enter the values in find what and replace what fields
  10. Click on the Replace All button.Click on the Replace ALL button

In the above data, it will change the text of four cells that have the text 2019 in it and also has a hyperlink.

Message Box to show the number of replacements

You can also use this technique to find all the cells with hyperlinks and get a list of it. To do this, instead of clicking on Replace All, click on the Find All button. This will instantly give you a list of all the cell address that has hyperlinks (or hyperlinks with specific text depending on what you’ve searched for).

Note: This technique works as Excel is able to identify the formatting of the cell that you select and use that as a criterion to find cells. So if you’re finding hyperlinks, make sure you select a cell that has the same kind of formatting. If you select a cell that has a background color or any text formatting, it may not find all the correct cells.

Selecting a Cell that has a Hyperlink in Excel

While Hyperlinks are useful, there are a few things about it that irritate me.

For example, if you want to select a cell that has a hyperlink in it, Excel would automatically open your default web browser and try to open this URL.

Another irritating thing about it is that sometimes when you have a cell that has a hyperlink in it, it makes the entire cell clickable. So even if you’re clicking on the hyperlinked text directly, it still opens the browser and the URL of the text.

So let me quickly show you how to get rid of these minor irritants.

Select the Cell (without opening the URL)

This is a simple trick.

When you hover the cursor over a cell that has a hyperlink in it, you’ll notice the hand icon (which indicates if you click on it, Excel will open the URL in a browser)

Hand Icon when you hover over a hyperlink cell

Click the cell anyway and hold the left button of the mouse.

After a second, you’ll notice that the hand cursor icon changes into the plus icon, and now when you leave it, Excel will not open the URL.

Plus icon when you hold the left mouse button

Instead, it would select the cell.

Now, you can make any changes in the cell you want.

Neat trick… right?

Select a Cell by clicking on the blank space in the cell

This is another thing that might drive you nuts.

When there is a cell with the hyperlink in it as well as some blank space, and you click on the blank space, it still opens the hyperlink.

Click hand icon when hover over white space of a cell

Here is a quick fix.

This happens when these cells have the wrap text enabled.

If you disable wrap text for these cells, you will be able to click on the white space on the right of the hyperlink without opening this link.

Some Practical Example of Using Hyperlink

There are useful things you can do when working with hyperlinks in Excel.

In this section, I am going to cover some examples that you may find useful and can use in your day-to-day work.

Example 1 – Create an Index of All Sheets in the Workbook

If you have a workbook with a lot of sheets, you can use a VBA code to quickly create a list of the worksheets and hyperlink these to the sheets.

This could be useful when you have 12-month data in 12 different worksheets and want to create one index sheet that links to all these monthly data worksheets.

Below is the code that will do this:

Sub CreateSummary()
'Created by Sumit Bansal of trumpexcel.com
'This code can be used to create summary worksheet with hyperlinks
Dim x As Worksheet
Dim Counter As Integer
Counter = 0
For Each x In Worksheets
Counter = Counter + 1
If Counter = 1 Then GoTo Donothing
    With ActiveCell
        .Value = x.Name
        .Hyperlinks.Add ActiveCell, "", x.Name & "!A1", TextToDisplay:=x.Name, ScreenTip:="Click here to go to the Worksheet"
        With Worksheets(Counter)
            .Range("A1").Value = "Back to " & ActiveSheet.Name
            .Hyperlinks.Add Sheets(x.Name).Range("A1"), "", _
            "'" & ActiveSheet.Name & "'" & "!" & ActiveCell.Address, _
            ScreenTip:="Return to " & ActiveSheet.Name
        End With
    End With
ActiveCell.Offset(1, 0).Select
Donothing:
Next x
End Sub

You can place this code in the regular module in the workbook (in VB Editor)

This code also adds a link to the summary sheet in cell A1 of all the worksheets. In case you don’t want that, you can remove that part from the code.

Creating Summary sheet with VBA

You can read more about this example here.

Note: This code works when you have the sheet (in which you want the summary of all the worksheets with links) at the beginning. In case it’s not at the beginning, this may not give the right results).

Example 2 – Create Dynamic Hyperlinks

In most cases, when you click on a hyperlink in a cell in Excel, it will take you to a URL or to a cell, file or folder. Normally, these are static URLs which means that a hyperlink will take you to a specific predefined URL/location only.

But you can also use a little bit for Excel formula trickery to create dynamic hyperlinks.

By dynamic hyperlinks, I mean links that are dependent on a user selection and change accordingly.

For example, in the below example, I want the hyperlink in cell E2 to point to the company website based on the drop-down list selected by the user (in cell D2).

This can be done using the below formula in cell E2:

=HYPERLINK(VLOOKUP(D2,$A$2:$B$6,2,0), "Click here")

The above formula uses the VLOOKUP function to fetch the URL from the table on the left. The HYPERLINK function then uses this URL to create a hyperlink in the cell with the text – ‘Click here’.

When you change the selection using the drop-down list, the VLOOKUP result will change and would accordingly link to the selected company’s website.

This could be a useful technique when you’re creating a dashboard in Excel. You can make the hyperlinks dynamic depending on the user selection (which could be a drop-down list or a checkbox or a radio button).

Here is a more detailed article of using Dynamic Hyperlinks in Excel.

Example 3 – Quickly Generate Simple Emails Using Hyperlink Function

As I mentioned in this article earlier, you can use the HYPERLINK function to quickly create simple emails (with pre-filled recipient’s emails and the subject line).

Single Recipient Email Id

=HYPERLINK("mailto:abc@trumpexcel.com","Generate Email")

This would open your default email client with the email id abc@trumpexcel.com in the ‘To’ field.

Multiple Recipients Email Id

=HYPERLINK("mailto:abc@trumpexcel.com,def@trumpexcel.com","Generate Email")

For sending the email to multiple recipients, use a comma to separate email ids. This would open the default email client with all the email ids in the ‘To’ field.

Add Recipients in CC and BCC List

=HYPERLINK("mailto:abc@trumpexcel.com,def@trumpexcel.com?cc=123@trumpexcel.com&bcc=456@trumpexcel.com","Generate Email")

To add recipients to CC and BCC list, use question mark ‘?’ when ‘mailto’ argument ends, and join CC and BCC with ‘&’. When you click on the link in excel, it would have the first 2 ids in ‘To’ field, 123@trumpexcel.com in ‘CC’ field and 456@trumpexcel.com in the ‘BCC’ field.

Add Subject Line

=HYPERLINK("mailto:abc@trumpexcel.com,def@trumpexcel.com?cc=123@trumpexcel.com&bcc=456@trumpexcel.com&subject=Excel is Awesome","Generate Email")

You can add a subject line by using the &Subject code. In this case, this would add ‘Excel is Awesome’ in the ‘Subject’ field.

Add Single Line Message in Body

=HYPERLINK("mailto:abc@trumpexcel.com,def@trumpexcel.com?cc=123@trumpexcel.com&bcc=456@trumpexcel.com&subject=Excel is Awesome&body=I love Excel","Email Trump Excel")

This would add a single line ‘I love Excel’ to the email message body.

Add Multiple Lines Message in Body

=HYPERLINK("mailto:abc@trumpexcel.com,def@trumpexcel.com?cc=123@trumpexcel.com&bcc=456@trumpexcel.com&subject=Excel is Awesome&body=I love Excel.%0AExcel is Awesome","Generate Email")

To add multiple lines in the body you need to separate each line with %0A. If you wish to introduce two line breaks, add %0A twice, and so on.

Here is a detailed article on how to send emails from Excel.

Hope you found this article useful.

Let me know your thoughts in the comments section.

You May Also Like the Following Excel Tutorials:

  • Excel AutoCorrect
  • How to Find External Links and References in Excel
  • 100+ Excel Interview Questions & Answers
  • Excel Text to Columns
  • Excel Sparklines

Let’s say you have a hyperlink in a cell in Excel. The hyperlink may have friendly text, such as Click Here, but when you click the link it takes you to a URL such as https://www.excel-university.com. Now, let’s say you want to extract that URL from the hyperlink using an Excel formula.

Well … to my knowledge, there isn’t a built-in function to accomplish that. But, we can actually create our own custom function, and even name it URL if we’d like, using a few lines of code. I’ll walk you through each step so it will be easy to implement. And thanks to my friend Cary who asked how to extract a url from a hyperlink which led to this post!

Overview

Before we get too far, let’s confirm what we are trying to accomplish. We have a hyperlink, or maybe several hyperlinks, in some Excel cells. Like this:

Excel workbook with Hyperlinks ... we want to extract the URL

We would like to be able to write some type of formula like =URL(B7) to extract the underlying URL from the links, like this:

The goal of extracting the urls from these hyperlinks with an excel formula

Although (at the time of this writing) Excel doesn’t have a built-in URL function, we can create our own custom URL function using a few lines of code.

I’ll break the entire process down into bite-sized steps. Ready? Let’s do this.

We’ll accomplish our objective with the following steps:

  • Create the URL function
  • Use the function to extract the URL
  • Save workbook as XLSM

Let’s start with creating the custom URL function.

Create the URL function

We’ll need to add our custom URL function to the workbook.

Note: if you want to skip this step, I already created the URL function in the Sample File below. So, rather than creating it yourself, you can certainly just download the workbook and get on with it. But, if you are curious about how it works, keep reading and I’ll explain the details.

The first thing we need to do is open the Visual Basic Editor. This can be accomplish by using the Alt+F11 keyboard shortcut in Excel for Windows, and I believe Opt+F11 (or Fn+Opt+F11) in Excel for Mac.

Next, we need to insert a new Module into the workbook. To do so, locate the workbook in the Project Explorer panel … it should say something like VBAProject (Workbookname) like this:

vba editor

Note: if you don’t see the Project Explorer panel, use the Ctrl+R keyboard shortcut to toggle it on.

Then, right-click the workbook name and select Insert > Module. You’ll see a new Module1 appear in a new folder called Modules, like this:

create a new module to store the custom function that extracts the url

Next, double-click Module1 so it opens. You’ll see a blank window that feels a little bit like a word-processor because you can type stuff there. You could type the custom function code, but it will be faster to copy/paste. So, copy this VBA code:

Function URL(Hyperlink As Range)
  URL = Hyperlink.Hyperlinks(1).Address
End Function

And then paste it into Module1. It should look like this:

this custom function extracts the url from a hyperlink using an excel formula

Believe it or not … the hard part is done!!!!!!!!!!!!!!!!

You can now toggle back to your Excel screen or close the Visual Basic Editor.

With the custom function complete, it is time to use it to extract the URLs from our hyperlinks.

Note: custom functions are stored inside workbooks rather than inside of the Excel application. This is good because other people that open the workbook can use the custom function. But, it also means you’ll either need to use this workbook for other URL extraction projects or create the custom function in other workbooks as needed.

To use the custom URL function, simply include it in a formula as you would with built-in functions. So, if our hyperlink was in B7, we could write the following formula in C7 to retrieve the URL from the hyperlink:

=URL(B7) 

Hit Enter, and bam…

Resulting function that retrieves the url from the hyperlink

We can also fill the formula down, and bam…

Fill the formula down to extract the url from each hyperlink in the range with an excel formula

With our mission accomplished, we need to chat about file types and custom code.

Save workbook as XLSM

When you try to save or close the workbook, you’ll probably get a message like this:

save as a macro-enabled workbook to reuse the code later

This is basically telling you that if you want to be able to use the custom URL function in the future, you’ll need to save it as an XLSM file type instead of the default XLSX which is a macro-free file type.

So, first click No to the dialog above, and then change the Save as type option to Excel Macro-Enabled Workbook (*.xlsm) like this:

excel macro-enabled workbook xlsm

Once done, it means that the custom function will be successfully saved in the workbook. In the future, if you (or anyone else) opens the file you will have the ability to use the custom URL function to extract the URLs from hyperlinks.

When you (or anyone else) opens the workbook in the future, you may receive a security warning like this:

security warning to enable macros to use it in the future

Be sure to Enable Content so that the URL function will work.


FREE: Excel Speed Challenge

If you enjoyed this post, please check out our free Excel speed challenge.

Watch one short Excel video a day for 5 days. Total video time is only 45 minutes. Learn the Excel skills that can help you save an hour a week.


Conclusion

Well, that is one way to extract a URL from a hyperlink using an Excel formula. If you have any other preferred methods or improvements to this one, please share by posting a comment below … thanks!

Sample file

Понравилась статья? Поделить с друзьями:
  • Get the address of a cell in excel vba
  • Get text in excel cell
  • Get templates in excel
  • Get stuck on a word
  • Get sheet name in excel sheet