Podcast #1729 - Hyperlink Hidden Pages

Cristinky420

New Member
Joined
Feb 13, 2019
Messages
17
Hey

I have followed all the coding for the podcast 1729 but am getting an error:

Runtime Error #9
Subscript out of range


using the following code

Private Sub Worksheet_FollowHyperlink(ByVal Target As Hyperlink)
LinkTo = Target.SubAddress
WhereBang = InStr(1, LinkTo, "!")
If WhereBang > 0 Then
MySheet = Left(LinkTo, WhereBang - 1)
Worksheets(MySheet).Visible = True
Worksheets(MySheet).Select
MyAddr = Mid(LinkTo, WhereBang + 1)
Worksheets(MySheet).Range(MyAddr).Select
End If



End Sub


Thanks for your help!
 
Last edited:

Excel Facts

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple
Is MySheet the name of the sheet?

If so..
Code:
Worksheets([COLOR=#ff0000][B]"[/B][/COLOR]MySheet[COLOR=#ff0000][B]"[/B][/COLOR]).Visible = True

For future posts...
The # icon above reply window adds code tags to your post.
Code is easier to read if code tags are used

[ CODE ] paste code here [ /CODE ]
 
Last edited:
Upvote 0
Yongle,
It is a string variable. It is defined in the line right above where they are using it.
Code:
[COLOR=#333333]MySheet = Left(LinkTo, WhereBang - 1)[/COLOR]

Cristinky420,
Are you referring to a MrExcel Podcast, or some other podcast?
 
Upvote 0
What is the name of the sheet that you are linking too?
If the sheet name has a space, is numerical, or is a valid cell reference, then the sheet name will be wrapped in single quotes which will cause the error.
 
Upvote 0
@Cristinky420

This happens on Excel 365...
Another way to make the code fail on that same line is to change the name of the linkTo Sheet AFTER creating the link
- you can easily test to see if this has happened by hovering over the link and checking if the sheet name in the little pop-up matches the actual name of the sheet
 
Last edited:
Upvote 0
I'm referring to the MrExcel podcast #1729

This is how the code reads on "Master"

[ CODE ] Private Sub Worksheet_FollowHyperlink(ByVal Target As Hyperlink)
LinkTo = Target.SubAddress
WhereBang = InStr(1, LinkTo, "!")
If WhereBang > 0 Then
MySheet = Left(LinkTo, WhereBang - 1)
Worksheets(MySheet).Visible = True
Worksheets(MySheet).Select
MyAddr = Mid(LinkTo, WhereBang + 1)
Worksheets(MySheet).Range(MyAddr).Select
End If [ /CODE ]

"MySheet" shows as '0126' like te sheet is numbered and the link leads to when the sheet is unhidden. Using Excel 2016.
 
Upvote 0
Try
Code:
mysheet = Replace(Left(LinkTo, WhereBang - 1), "'", "")
 
Upvote 0
You're welcome & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,214,641
Messages
6,120,691
Members
448,978
Latest member
rrauni

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