VBA Hyperlink Cells to Sheet

Bablu

Board Regular
Joined
Dec 9, 2008
Messages
131
Office Version
  1. 2016
Platform
  1. Windows
Hi All-

I modified a piece of code to hyperlink each cell to a particular sheet. Now the code works fine if the cell (name of the sheet) does not have any space. For example, if I have a sheet called "Sheet1" then it would link, but if I have a sheet called "Sheet1 Updated", the code does not link.

Any help would be great. Below is the code.

Dim nameRange As Range
Dim thisCell As Range

Set nameRange = Selection

For Each cl In nameRange
Set thisCell = cl

ActiveSheet.Hyperlinks.Add _
Anchor:=ActiveCell.Offset(0, -5), _
Address:="", _
SubAddress:="" & cl.Value & "!A1", _
TextToDisplay:=ActiveCell.Offset(0, -5).Value
Next cl

Thanks,

Bablu
 

Excel Facts

Show numbers in thousands?
Use a custom number format of #,##0,K. Each comma after the final 0 will divide the displayed number by another thousand
If a sheet has spaces, u need ' surrounding it

Sheet1!H1

'Sheet With Spaces'!H1

SubAddress:="'" & cl.Value & "'!A1", _
 
Upvote 0

Forum statistics

Threads
1,224,522
Messages
6,179,299
Members
452,904
Latest member
CodeMasterX

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top