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

Get FREE Advanced Excel Exercises with Solutions!

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

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


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

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

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


Related Articles

What is ExcelDemy?

ExcelDemy - Learn Excel & Get Excel Solutions Center provides online Excel training , Excel consultancy services , free Excel tutorials, free support , and free Excel Templates for Excel professionals and businesses. Feel free to contact us with your Excel problems.
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