In this article, I’ll show you how you can 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
Excel VBA: Add Hyperlink to Cell in Another Sheet: 2 Effective Examples
So without further delay, let’s move to our main discussion today. You can add a hyperlink to a cell in another sheet in 2 possible ways.
1. Add Hyperlink to Cell in Another Sheet Directly with Excel VBA
First of all, you 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” to cell B4 of the worksheet Sheet1 of the workbook.
⧭ Note:
Though this is the most simple method, it is not quite useful in practical circumstances. While working with hyperlinks, most often we need to insert the link in the disguise of another text. But we can’t accomplish this using this method.
Read More: VBA to Add Hyperlink to Cell Value in Excel
2. Add Hyperlink to Cell in Another Sheet with the Hyperlinks.Add Property of Excel VBA
We found that the previous method was pretty simple, but it was not quite useful in practical situations.
Now we’ll learn the method that’s a bit complex but will come in quite handy in useful situations.
Let’s try to insert the link “www.exceldemy.com” again in cell B4 of the worksheet Sheet2, in the disguise of the text “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 of the hyperlink. Here it’s Worksheets(“Sheet2”).Range(“D4”).
- Address: The hyperlink. Here it’s exceldemy.com.
- [Sub Address]: Location of the page. Optional. We’ll not use it here.
- [Screen Tip]: Value to be shown when a mouse pointer is placed. Optional. We’ll not use it.
- [TextToDisplay]: The text that’ll be shown on 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” to cell B4 of the worksheet Sheet2 of the workbook in the disguise of the text “Site Address”.
Things to Remember
In this article, I’ve focused on adding a hyperlink to a cell only. If you want to know more about Excel hyperlinks, you can visit this link.
Download Practice Workbook
Conclusion
So these are the ways to add a hyperlink to a cell in an Excel worksheet with VBA. Do you know any other method? Feel free to ask us.