Excel Tips from Xlteq - Using Hyerlinks to Run Code
There are two ways you can run VBA code using Hyperlinks in Excel, either by clicking on the hyperlink or moving the mouse over the link.
There are two ways you can run VBA code using Hyperlinks in Excel, either by clicking on the hyperlink or moving the mouse over the link.
To run some code when clicking on a hyperlink, the following steps should be taken.
1. Type in the text you want to see in the cell you want it to appear in.
2. Then right click on the cell and choose the options “Link” and then “Insert Link…”
3. A window will open:
4. Enter Visual Basic and double click on the sheet in the Project Explorer to bring up the sheet code
5. Select “Worksheet” and “FollowHyperlink” from the dropdowns to create the Sub.
6. Then enter the following code
If Target.Range.Address = "B2" Then Call YourCodeToRun
Where “B2” refers to the cell you entered the text on the sheet and “YourCodeToRun” is the name of the sub you want to run
You can also call code when you move your mouse over a hyperlink.
1. Create a Function (not a sub) which has the code you want to run (the function is called Test() in the following example)2. Enter the following into the cell you want to have the hyperlink in
Either call us now on 020 3817 6945 or fill out the form below and one of our team will be in touch.