HYPER LINK COMMAND BUTTON

charly1

Board Regular
Joined
Jul 18, 2023
Messages
87
Office Version
  1. 365
Platform
  1. Windows
Hi

I have a formule entered into a cell with a dynamic hyperlink copied below:

=HYPERLINK("#"&"מפתח!E"&(XMATCH(B4,BOOK)+12),"Hello")

My question is, is there a way I can insert a a command button into my sheet to run the hyperlink contained in the cell?

Thanks so much.
 

Excel Facts

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.
Can you explain 'run the hyperlink contained in the cell' a bit more?

Does clicking on the link not run the hyperlink?
 
Upvote 0
Can you explain 'run the hyperlink contained in the cell' a bit more?

Does clicking on the link not run the hyperlink?
It does actually work when i click on the link, its just that for my dashboard i would like a command button to act as though ive clicked on that cell link.
Thanks so much
 
Upvote 0
I see, perhaps the below will work for you:
VBA Code:
Sub test()
    Dim ws As Worksheet
    Dim rCell As Range
    Dim re As Object
    
    Set ws = Sheets("Sheet1")
    Set rCell = ws.Range("A1")
    
    Set re = CreateObject("VBScript.RegExp")
    re.Pattern = "^=HYPERLINK\(""([^""]+)"""
    
    If re.test(rCell.Formula) Then
        ThisWorkbook.FollowHyperlink re.Execute(rCell.Formula)(0).SubMatches(0)
    End If
End Sub
 
Upvote 0
I see, perhaps the below will work for you:
VBA Code:
Sub test()
    Dim ws As Worksheet
    Dim rCell As Range
    Dim re As Object
   
    Set ws = Sheets("Sheet1")
    Set rCell = ws.Range("A1")
   
    Set re = CreateObject("VBScript.RegExp")
    re.Pattern = "^=HYPERLINK\(""([^""]+)"""
   
    If re.test(rCell.Formula) Then
        ThisWorkbook.FollowHyperlink re.Execute(rCell.Formula)(0).SubMatches(0)
    End If
End Sub
I placed this code into the command button, but it doesn't seem to work.

I am new to excel though, so the fault is likely mine!

I also tried to change the A1 reference in your code to the cell address of the formula but it still didn't help

Thanks so much for your patience and time.
 
Upvote 0
I also tried to change the A1 reference in your code to the cell address of the formula
What is that cell address?
You will have to do the same thing with this code but give it a try.
Not sure if you will want the Scroll:=True?

VBA Code:
Sub Testing()
  Dim s As String, f As String
 
  f = Replace(Range("A1").Formula, "'", "")
  s = Evaluate(Left(f, InStrRev(f, ",") - 1) & ")")
  Application.Goto Reference:=Sheets(Mid(Split(s, "!")(0), 2)).Range(Split(s, "!")(1)), Scroll:=True
End Sub
 
Upvote 0
Solution
When placing the code into a command button, only place the code between the Sub & End Sub lines, do not include those lines. You may have to amend the sheet name also.

The code will look like the below:
VBA Code:
Private Sub CommandButton1_Click()
    Dim ws As Worksheet
    Dim rCell As Range
    Dim re As Object
    
    Set ws = Sheets("Sheet1")
    Set rCell = ws.Range("A1")
    
    Set re = CreateObject("VBScript.RegExp")
    re.Pattern = "^=HYPERLINK\(""([^""]+)"""
    
    If re.test(rCell.Formula) Then
        ThisWorkbook.FollowHyperlink re.Execute(rCell.Formula)(0).SubMatches(0)
    End If
End Sub
 
Upvote 0
What is that cell address?
You will have to do the same thing with this code but give it a try.
Not sure if you will want the Scroll:=True?

VBA Code:
Sub Testing()
  Dim s As String, f As String
 
  f = Replace(Range("A1").Formula, "'", "")
  s = Evaluate(Left(f, InStrRev(f, ",") - 1) & ")")
  Application.Goto Reference:=Sheets(Mid(Split(s, "!")(0), 2)).Range(Split(s, "!")(1)), Scroll:=True
End Sub
Thanks a mil! It worked like a charm!
 
Upvote 0
You're welcome. Thanks for the follow-up. :)

@Georgiboy
I couldn't get your code to work in my test workbook either.
 
Upvote 0
How strange, working my end. Oh well a solution has been found, that's the main thing.
 
Upvote 0

Forum statistics

Threads
1,215,103
Messages
6,123,106
Members
449,096
Latest member
provoking

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