Private Sub Worksheet_Change(Target As Range)
Dim Cell As Range
Dim Text As String
Text = "My Text"
If Target.Cells.Count > 1 Then Exit Sub
If Target.Value = Text Then
Call Macro1
End If
End Sub
[COLOR=#242729][FONT=Arial]es you can, follow the below Simple Steps to do so:
[/FONT][/COLOR][COLOR=#242729][FONT=Arial]Step 1. Select the Cell Where you want to make the Hyperlink
Step 2. Righ Click –> Hyperlink…
Step 3. Enter the Address of the Same cell where you are making the hyperlink and Give name to the Link. [/FONT][/COLOR]
[COLOR=#242729][FONT=Arial]Step 4. Click Ok. Step 5. HyperLink is created.
[/FONT][/COLOR]
[COLOR=#242729][FONT=Arial]Note: Clicking on this Hyperlink, will do nothing because it is assigned to the same Cell Address.[/FONT][/COLOR]
[COLOR=#242729][FONT=Arial]
Step 6. Now Press Alt + F11
Step 7. Copy paste the below Code[/FONT][/COLOR]
[COLOR=#242729][FONT=Arial]Run Excel Macro by Clicking on a Hyperlink
[/FONT][/COLOR]
<code style="margin: 0px; padding: 0px; border: 0px; font-family: Consolas, Menlo, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace, sans-serif; white-space: inherit;">[COLOR=#101094]Private[/COLOR][COLOR=#101094]Sub[/COLOR][COLOR=#303336] Worksheet_FollowHyperlink[/COLOR][COLOR=#303336]([/COLOR][COLOR=#101094]ByVal[/COLOR][COLOR=#303336] Target [/COLOR][COLOR=#101094]As[/COLOR][COLOR=#303336] Hyperlink[/COLOR][COLOR=#303336])[/COLOR][COLOR=#303336]
[/COLOR][COLOR=#858C93]'Check if the Target Address is same as you have given [/COLOR][COLOR=#303336]
[/COLOR][COLOR=#858C93]'In the above example i have taken A4 Cell, so I am [/COLOR][COLOR=#303336]
[/COLOR][COLOR=#858C93]'Comparing this with $A$4 [/COLOR][COLOR=#303336]
[/COLOR][COLOR=#101094]If[/COLOR][COLOR=#303336] Target[/COLOR][COLOR=#303336].[/COLOR][COLOR=#303336]Range[/COLOR][COLOR=#303336].[/COLOR][COLOR=#303336]Address [/COLOR][COLOR=#303336]=[/COLOR][COLOR=#7D2727]"$A$4"[/COLOR][COLOR=#101094]Then[/COLOR][COLOR=#303336]
[/COLOR][COLOR=#858C93]'Write your all VBA Code, which you want to execute [/COLOR][COLOR=#303336]
[/COLOR][COLOR=#858C93]'Or Call the function or Macro which you have [/COLOR][COLOR=#303336]
[/COLOR][COLOR=#858C93]'written or recorded. [/COLOR][COLOR=#303336]
MsgBox [/COLOR][COLOR=#7D2727]"Write your Code here to be executed"[/COLOR][COLOR=#303336]
[/COLOR][COLOR=#101094]Exit[/COLOR][COLOR=#101094]Sub[/COLOR][COLOR=#303336]
[/COLOR][COLOR=#101094]End[/COLOR][COLOR=#101094]If[/COLOR][COLOR=#303336]
[/COLOR][COLOR=#101094]End[/COLOR][COLOR=#101094]Sub
[/COLOR]</code>[COLOR=#242729][FONT=Arial]In the Above Code we are comparing the Cell Address and then Executing a Set of Code or Function. There is another way of doing this also. We can Compare with the Target Name and execute the Code.
In the above Example as i have given the Name of the Hyperlink Target as MyMacro.
[/FONT][/COLOR]
<code style="margin: 0px; padding: 0px; border: 0px; font-family: Consolas, Menlo, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace, sans-serif; white-space: inherit;">[COLOR=#101094]Private[/COLOR][COLOR=#101094]Sub[/COLOR][COLOR=#303336] Worksheet_FollowHyperlink[/COLOR][COLOR=#303336]([/COLOR][COLOR=#101094]ByVal[/COLOR][COLOR=#303336] Target [/COLOR][COLOR=#101094]As[/COLOR][COLOR=#303336] Hyperlink[/COLOR][COLOR=#303336])[/COLOR][COLOR=#303336]
[/COLOR][COLOR=#858C93]'Check if the Target Name is same as you have given [/COLOR][COLOR=#303336]
[/COLOR][COLOR=#858C93]'In the above example i have given the Name of the HyperLink [/COLOR][COLOR=#303336]
[/COLOR][COLOR=#858C93]'is MyMacro. [/COLOR][COLOR=#303336]
[/COLOR][COLOR=#101094]If[/COLOR][COLOR=#303336] Target[/COLOR][COLOR=#303336].[/COLOR][COLOR=#303336]Name [/COLOR][COLOR=#303336]=[/COLOR][COLOR=#7D2727]"mymacro"[/COLOR][COLOR=#101094]Then[/COLOR][COLOR=#303336]
[/COLOR][COLOR=#858C93]'Write your all VBA Code, which you want to execute [/COLOR][COLOR=#303336]
[/COLOR][COLOR=#858C93]'Or Call the function or Macro which you have [/COLOR][COLOR=#303336]
[/COLOR][COLOR=#858C93]'written or recorded. [/COLOR][COLOR=#303336]
MsgBox [/COLOR][COLOR=#7D2727]"Write your Code here to be executed"[/COLOR][COLOR=#303336]
[/COLOR][COLOR=#101094]Exit[/COLOR][COLOR=#101094]Sub[/COLOR][COLOR=#303336]
[/COLOR][COLOR=#101094]End[/COLOR][COLOR=#101094]If[/COLOR]</code>[COLOR=#101094][FONT=Consolas]End[/FONT][/COLOR][COLOR=#101094][FONT=Consolas]Sub[/FONT][/COLOR]
Here is an example (I haven't tried it yet). Very simple ... test it out.
Code:[COLOR=#242729][FONT=Arial]es you can, follow the below Simple Steps to do so: [/FONT][/COLOR][COLOR=#242729][FONT=Arial]Step 1. Select the Cell Where you want to make the Hyperlink Step 2. Righ Click –> Hyperlink… Step 3. Enter the Address of the Same cell where you are making the hyperlink and Give name to the Link. [/FONT][/COLOR] [COLOR=#242729][FONT=Arial]Step 4. Click Ok. Step 5. HyperLink is created. [/FONT][/COLOR] [COLOR=#242729][FONT=Arial]Note: Clicking on this Hyperlink, will do nothing because it is assigned to the same Cell Address.[/FONT][/COLOR] [COLOR=#242729][FONT=Arial] Step 6. Now Press Alt + F11 Step 7. Copy paste the below Code[/FONT][/COLOR] [COLOR=#242729][FONT=Arial]Run Excel Macro by Clicking on a Hyperlink [/FONT][/COLOR] <code style="margin: 0px; padding: 0px; border: 0px; font-family: Consolas, Menlo, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace, sans-serif; white-space: inherit;">[COLOR=#101094]Private[/COLOR][COLOR=#101094]Sub[/COLOR][COLOR=#303336] Worksheet_FollowHyperlink[/COLOR][COLOR=#303336]([/COLOR][COLOR=#101094]ByVal[/COLOR][COLOR=#303336] Target [/COLOR][COLOR=#101094]As[/COLOR][COLOR=#303336] Hyperlink[/COLOR][COLOR=#303336])[/COLOR][COLOR=#303336] [/COLOR][COLOR=#858C93]'Check if the Target Address is same as you have given [/COLOR][COLOR=#303336] [/COLOR][COLOR=#858C93]'In the above example i have taken A4 Cell, so I am [/COLOR][COLOR=#303336] [/COLOR][COLOR=#858C93]'Comparing this with $A$4 [/COLOR][COLOR=#303336] [/COLOR][COLOR=#101094]If[/COLOR][COLOR=#303336] Target[/COLOR][COLOR=#303336].[/COLOR][COLOR=#303336]Range[/COLOR][COLOR=#303336].[/COLOR][COLOR=#303336]Address [/COLOR][COLOR=#303336]=[/COLOR][COLOR=#7D2727]"$A$4"[/COLOR][COLOR=#101094]Then[/COLOR][COLOR=#303336] [/COLOR][COLOR=#858C93]'Write your all VBA Code, which you want to execute [/COLOR][COLOR=#303336] [/COLOR][COLOR=#858C93]'Or Call the function or Macro which you have [/COLOR][COLOR=#303336] [/COLOR][COLOR=#858C93]'written or recorded. [/COLOR][COLOR=#303336] MsgBox [/COLOR][COLOR=#7D2727]"Write your Code here to be executed"[/COLOR][COLOR=#303336] [/COLOR][COLOR=#101094]Exit[/COLOR][COLOR=#101094]Sub[/COLOR][COLOR=#303336] [/COLOR][COLOR=#101094]End[/COLOR][COLOR=#101094]If[/COLOR][COLOR=#303336] [/COLOR][COLOR=#101094]End[/COLOR][COLOR=#101094]Sub [/COLOR]</code>[COLOR=#242729][FONT=Arial]In the Above Code we are comparing the Cell Address and then Executing a Set of Code or Function. There is another way of doing this also. We can Compare with the Target Name and execute the Code. In the above Example as i have given the Name of the Hyperlink Target as MyMacro. [/FONT][/COLOR] <code style="margin: 0px; padding: 0px; border: 0px; font-family: Consolas, Menlo, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace, sans-serif; white-space: inherit;">[COLOR=#101094]Private[/COLOR][COLOR=#101094]Sub[/COLOR][COLOR=#303336] Worksheet_FollowHyperlink[/COLOR][COLOR=#303336]([/COLOR][COLOR=#101094]ByVal[/COLOR][COLOR=#303336] Target [/COLOR][COLOR=#101094]As[/COLOR][COLOR=#303336] Hyperlink[/COLOR][COLOR=#303336])[/COLOR][COLOR=#303336] [/COLOR][COLOR=#858C93]'Check if the Target Name is same as you have given [/COLOR][COLOR=#303336] [/COLOR][COLOR=#858C93]'In the above example i have given the Name of the HyperLink [/COLOR][COLOR=#303336] [/COLOR][COLOR=#858C93]'is MyMacro. [/COLOR][COLOR=#303336] [/COLOR][COLOR=#101094]If[/COLOR][COLOR=#303336] Target[/COLOR][COLOR=#303336].[/COLOR][COLOR=#303336]Name [/COLOR][COLOR=#303336]=[/COLOR][COLOR=#7D2727]"mymacro"[/COLOR][COLOR=#101094]Then[/COLOR][COLOR=#303336] [/COLOR][COLOR=#858C93]'Write your all VBA Code, which you want to execute [/COLOR][COLOR=#303336] [/COLOR][COLOR=#858C93]'Or Call the function or Macro which you have [/COLOR][COLOR=#303336] [/COLOR][COLOR=#858C93]'written or recorded. [/COLOR][COLOR=#303336] MsgBox [/COLOR][COLOR=#7D2727]"Write your Code here to be executed"[/COLOR][COLOR=#303336] [/COLOR][COLOR=#101094]Exit[/COLOR][COLOR=#101094]Sub[/COLOR][COLOR=#303336] [/COLOR][COLOR=#101094]End[/COLOR][COLOR=#101094]If[/COLOR]</code>[COLOR=#101094][FONT=Consolas]End[/FONT][/COLOR][COLOR=#101094][FONT=Consolas]Sub[/FONT][/COLOR]
Here is the link to the article:
In Excel, can I use a hyperlink to run vba macro? - Stack Overflow