Yes, you can follow these simple steps:
Step 1. Select the cell in which you want to make a hyperlink Step 2. Righ Click → Hyperlink ... Step 3. Enter the address of the same cell where you make the hyperlink and specify the name of the link. See image below:
Assign macro to hyperlink
Step 4. Click OK. Step 5. HyperLink is created.
Note. Clicking on this hyperlink will do nothing, because it has the same cell address.
Step 6. Now press Alt + F11. Step 7. Copy the paste below the code.
Run the Excel macro by clicking on the hyperlink
Private Sub Worksheet_FollowHyperlink(ByVal Target As Hyperlink) 'Check if the Target Address is same as you have given 'In the above example i have taken A4 Cell, so I am 'Comparing this with $A$4 If Target.Range.Address = "$A$4" Then 'Write your all VBA Code, which you want to execute 'Or Call the function or Macro which you have 'written or recorded. MsgBox "Write your Code here to be executed" Exit Sub End If End Sub
In the above code, we compare the address of the cell, and then perform a set of code or function. There is another way to do this. We can compare with the target name and execute the code. In the above example, since I gave the name of the hyperlink object as MyMacro.
Private Sub Worksheet_FollowHyperlink(ByVal Target As Hyperlink) 'Check if the Target Name is same as you have given 'In the above example i have given the Name of the HyperLink 'is MyMacro. If Target.Name = "mymacro" Then 'Write your all VBA Code, which you want to execute 'Or Call the function or Macro which you have 'written or recorded. MsgBox "Write your Code here to be executed" Exit Sub End If End Sub
MM
source share