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
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
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
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