Hyperlink to hidden sheet - target.name does not return value??

imhoffp

New Member
Joined
Apr 6, 2022
Messages
3
Office Version
  1. 2019
Platform
  1. Windows
this code will not work in my spreadsheet... trying to hyperlink to a hidden sheet. The error is on the 3rd line. I believe the shtname does not have a value. I have the VB in the worksheet under follow hyperlink. What am I missing?

dim shtname as string
shtname=target.name
sheets(shtname).visible=xlsheetvisible
sheets(shtname).select
 

Excel Facts

What does custom number format of ;;; mean?
Three semi-colons will hide the value in the cell. Although most people use white font instead.
Please show the entire sub. How is Target defined? If it is a Range parameter to a Sub then you need this:

Rich (BB code):
shtname=target.parent.name

I would skip dealing with the name altogether and do this:
VBA Code:
dim sht as Worksheet
Set sht = Target.Parent
sht.Visible=xlsheetvisible
sht.select
 
Upvote 0
thanks... here is the entire code I'm using based on another suggestion. When run, no error but does not jump to the other sheet

Private Sub Worksheet_FollowHyperlink(ByVal Target As Hyperlink)

Dim ShtName As String
ShtName = Left(Target.SubAddress, InStr(1, Target.SubAddress, "!") - 1)
Sheets(ShtName).Visible = xlSheetVisible
Sheets(ShtName).Select

End Sub
 
Upvote 0
Your sheet name probably contains spaces, try the below.

VBA Code:
Private Sub Worksheet_FollowHyperlink(ByVal Target As Hyperlink)
    Dim ShtName As String
    ShtName = VBA.Replace(VBA.Left(Target.SubAddress, VBA.InStr(1, Target.SubAddress, "!") - 1), "'", "")
    Sheets(ShtName).Visible = xlSheetVisible
    Sheets(ShtName).Select
End Sub
 
Upvote 0

Forum statistics

Threads
1,215,338
Messages
6,124,343
Members
449,155
Latest member
ravioli44

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