Help with code to run macros from hyperlinks

M

Monomeeth

Hello

I am using the following code to run a macro from a hyperlink located in
cell B13.


Private Sub Worksheet_FollowHyperlink(ByVal Target As Hyperlink)
If Not Intersect(Target.Parent, Range("B13")) Is Nothing Then
JacDetailedAnalysisTable
End If
End Sub


The above works fine, but I want to be able to have multiple hyperlinks,
each of which runs a different macro. All of the hyperlinks are on the same
worksheet.

How do I modify the code to achieve this?

I tried repeating the code multiple times, changing the cell reference and
subroutine name for each hyperlink, but this caused all sorts of problems.

Your help would be greatly appreciated.

Thanks,

Joe.
 
P

Per Jessen

Hi Joe

You can only have one instance of the event code in a workbook, so you have
to make multiple if-then statements within it.

Look at my example:

Private Sub Worksheet_FollowHyperlink(ByVal Target As Hyperlink)
If Not Intersect(Target.Parent, Range("B13")) Is Nothing Then
JacDetailedAnalysisTable
End If
If Not Intersect(Target.Parent, Range("B14")) Is Nothing Then
CallOtherMacro
End If
End Sub

Regards,
Per
 
M

Monomeeth

Hi Per

Thank you VERY MUCH for this. It seems to work perfectly!

To be honest, when I first read it I thought to myself "that's exactly what
I tried and it didn't work" - but obviously I must have missed something
because it works a treat.

Thanks again for your help!

Joe.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top