Excel VBA: Add Hyperlink to Cell in Another Sheet (2 Examples)

In this article, we’ll demonstrate how to add a hyperlink to a cell in another sheet using VBA in Excel.


Excel VBA: Add Hyperlink to Cell in Another Sheet (Quick View)

Sub Hyperlink_with_Hyperlink_Property()

Worksheets("Sheet1").Range("D4").Hyperlinks.Add _
                                                  Anchor:=Range("D4"), _
                                                  Address:="www.exceldemy.com", _
                                                  TextToDisplay:="Site Address"

End Sub

VBA Code to Add Hyperlink to a Cell in Another Sheet with Excel VBA

Here are 2 ways to add a hyperlink to a cell in another sheet.


Method 1 – Adding a Hyperlink Directly with Excel VBA

We can add a hyperlink to a cell in a worksheet directly with Excel VBA.

For example, let’s add the link www.exceldemy.com” to cell B4 of the worksheet Sheet1 of the workbook. The VBA code will be:

VBA Code:

Sub Add_Hyperlink()
Worksheets("Sheet1").Range("B4") = "www.exceldemy.com"
End Sub

VBA Code to Add Hyperlink to a Cell in Another Sheet in Excel

Output:

Run this code. It’ll insert the link www.exceldemy.com” into cell B4 of the worksheet Sheet1 of the workbook.

Note:

Although this is the most simple method, it’s not suitable when we need to insert the link with a different label.

Read More: VBA to Add Hyperlink to Cell Value in Excel


Method 2 – Using the Hyperlinks.Add Property of Excel VBA

This method is more complex but flexible.

Let’s insert the link www.exceldemy.com” again in cell B4 of the worksheet Sheet2, but this time with the label “Site Address”.

We’ll use the Hyperlinks. Add method of VBA for this purpose.

The Hyperlinks. Add method takes a total of 5 arguments:

  • Anchor: The location to place the hyperlink. Here it’s Worksheets(“Sheet2”).Range(“D4”).
  • Address: The hyperlink. Here it’s exceldemy.com.
  • [Sub Address]: The location of the page. Optional. We don’t need it here.
  • [Screen Tip]: The value to be shown when a mouse hovers on the link. Optional, and not used here.
  • [TextToDisplay]: The text that’ll be shown in the cell. Optional. Here it’s Site Address.

Therefore, the VBA code will be:

VBA Code:

Sub Hyperlink_with_Hyperlink_Property()

Worksheets("Sheet2").Range("D4").Hyperlinks.Add _
                                                  Anchor:=Worksheets("Sheet2").Range("D4"), _
                                                  Address:="www.exceldemy.com", _
                                                  TextToDisplay:="Site Address"

End Sub

VBA Code to Add Hyperlink to a Cell in Another Sheet with Excel VBA

Output:

Run this code. It’ll insert the link www.exceldemy.com” in cell B4 of the worksheet Sheet2 of the workbook with the label “Site Address”.


Things to Remember

To know more about Excel hyperlinks, visit this link.


Download Practice Workbook


Related Articles

Get FREE Advanced Excel Exercises with Solutions!
Rifat Hassan
Rifat Hassan

Rifat Hassan, BSc, Electrical and Electronic Engineering, Bangladesh University of Engineering and Technology, has worked with the ExcelDemy project for almost 2 years. Within these 2 years, he has written over 250 articles. He has also conducted a few Boot Camp sessions on effective coding, especially Visual Basic for Applications (VBA). Currently, he is working as a Software Developer to develop and deploy additional add-ins to enhance the customers with a more sophisticated experience with Microsoft Office Suits,... Read Full Bio

We will be happy to hear your thoughts

Leave a reply

Advanced Excel Exercises with Solutions PDF

 

 

ExcelDemy
Logo