Variable Hyperlink in VB

russelldt

Board Regular
Joined
Feb 27, 2021
Messages
158
Office Version
  1. 365
Platform
  1. MacOS
Hello

I hope some genius out there can help me.

I have a cell in sheet 1(call it the source cell), hyperlinked to a hidden sheet. The text in the source cell and Sheet Name are the same, so when i select the cell, the hidden sheet opens. Here is the VB routine i am using:


Private Sub Worksheet_FollowHyperlink(ByVal Target As Hyperlink)

Dim shtName As String
shtName = Target.Name

Sheets(shtName).Visible = xlSheetVisible
Sheets(shtName).Select
End Sub


I now have a dropdown menu in the source cell and I have to select different text depending on which sheet i want to access by the hyperlink. There is always a unique sheet for the different text options. I just can't get this to work.

Looking for help. please

Thanks
 

Excel Facts

How to calculate loan payments in Excel?
Use the PMT function: =PMT(5%/12,60,-25000) is for a $25,000 loan, 5% annual interest, 60 month loan.
Please share small sample data along with sheet names
 
Upvote 0
Thanks for the response.

The dropdown menu looks like the image below, and the sheet names are"Tub", "Shower" and "Tub and Shower". All the sheets are hidden, and I want to be able to open the hidden sheet corresponding to the selection in the drop down menu.
 

Attachments

  • Screen Shot 2021-09-03 at 08.02.22.png
    Screen Shot 2021-09-03 at 08.02.22.png
    91.5 KB · Views: 13
Upvote 0
How about
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
   If Target.CountLarge > 1 Then Exit Sub
   If Target.Address(0, 0) = "A3" Then
      If Evaluate("isref('" & Target.Value & "'!A1)") Then
         Sheets(Target.Value).Visible = xlSheetVisible
      Else
         MsgBox "Sheet " & Target.Value & " does not exist"
      End If
   End If
End Sub
 
Upvote 0
Thanks Fluff.

Next question, how do i set up the hyperlink in cell A2 (above picture)?
 
Upvote 0
Why do you need a hyperlink?
 
Upvote 0
I guess, because that's how it is set up at present. I was using the hyperlink and above VB script to open the hidden spreadsheet, but now i want to be able to open a different sheet, based on the options in the dropdown (all hidden sheets).
 
Upvote 0
Thanks Fluff.

Next question, how do i set up the hyperlink in cell A2 (above picture)?
So I see that the VB unhides the actual sheet, it does not open the sheet, as a Hyperlink does. That is what the hperlink did, opened the sheet at A1
 
Upvote 0
If you want to do that, how about
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
   If Target.CountLarge > 1 Then Exit Sub
   If Target.Address(0, 0) = "A3" Then
      If Evaluate("isref('" & Target.Value & "'!A1)") Then
         With Sheets(Target.Value)
            .Visible = xlSheetVisible
            Application.Goto .Range("A1"), True
         End With
      Else
         MsgBox "Sheet " & Target.Value & " does not exist"
      End If
   End If
End Sub
 
Upvote 0
You are a genius, many thanks.

If / when i move the dropdown from A3 to a different cell, (i have about 20 of these dropdown cells all opening different bespoke sheets), how do i change the VB script
 
Upvote 0

Forum statistics

Threads
1,215,460
Messages
6,124,949
Members
449,198
Latest member
MhammadishaqKhan

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