Run Time error 9 - Subscript out of range

JJMUTT

New Member
Joined
Sep 25, 2017
Messages
1
I am a novice VBA user. I have a menu page with different cells that all hyperlink to hidden sheets. All sheets unhide except a few that give me the "Run Time error 9 - Subscript out of range". Where is my error? Thank you for looking! Below is a pic of the debug (Error is in RED) line and the code:

Private Sub Worksheet_FollowHyperlink(ByVal Target As Hyperlink)

Dim strSheet As String

If InStr(Target.Parent, "!") > 0 Then
strSheet = Left(Target.Parent, InStr(1, Target.Parent, "!") - 1)


Else
strSheet = Target.Parent
End If

Sheets(strSheet).Visible = True

Sheets(strSheet).Select

End Sub
Private Sub Worksheet_Activate()

Dim ws As Excel.Worksheet

For Each ws In ThisWorkbook.Worksheets
If ws.Name = "Instructions" Then
ws.Visible = True
ElseIf ws.Name = "IRA Matrix" Then
ws.Visible = True
ElseIf ws.Name = "Activity List" Then
ws.Visible = True
Else
ws.Visible = (ws.Name = Me.Name)
End If
Next

End Sub
 

Excel Facts

How to create a cell-sized chart?
Tiny charts, called Sparklines, were added to Excel 2010. Look for Sparklines on the Insert tab.
The error means that a sheet with name was not found. Place a breakpoint in your code and check values being assigned to strSheet variable; or temporarily add a msgbox statement to display its value.
 
Upvote 0
The parent of a Hyperlink is a String of the URL or link location (including at least sheet and cell). It is unlikely to be just a sheet name.
 
Upvote 0

Forum statistics

Threads
1,223,909
Messages
6,175,314
Members
452,634
Latest member
cpostell

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