Trigger a macro via a hyperlink

ifu06416

Board Regular
Joined
Sep 5, 2011
Messages
56
Office Version
  1. 365
Hi there,

I have a series of hyperlinks on a tab that when clicked i want to hide/unhide specific rows.

I have looked around online and realize i cannot have more than one Worksheet_FollowHyperlink but that i can build a macro that calls on other macros to work around this.

i have built three simple macros (macro1, macro2 and macro3) for hiding/unhiding the rows but the macro i have that is supposed to call on them doesn't seem to work. I know macro1, macro2 and macro3 work as they hide the rows when triggered manually.

the code i have written so far is;

Private Sub Worksheet_FollowHyperlink(ByVal Target As Hyperlink) If Target.Range.Address = "$c$3" Then
Call macro1
End If
If Target.Range.Address = "$B$6" Then
Call macro2
End If
If Target.Range.Address = "$d$3" Then
Call macro3
End If
End Sub
Sub macro1()


Rows("6:9").Select
If Selection.EntireRow.Hidden = True Then
Selection.EntireRow.Hidden = False
Else
Selection.EntireRow.Hidden = True


End If


End Sub
Sub macro2()

Rows("20:25").Select
If Selection.EntireRow.Hidden = True Then
Selection.EntireRow.Hidden = False
Else
Selection.EntireRow.Hidden = True


End If


End Sub
Sub macro3()

Rows("12:15").Select
If Selection.EntireRow.Hidden = True Then
Selection.EntireRow.Hidden = False
Else
Selection.EntireRow.Hidden = True


End If


End Sub

can anyone help in linking these all together?

Regards,

John
 

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.
John

Address always returns the address in upper case so you'll need to change '$c$3' and '$d$3' to '$C$3' and '$D$3' respectively.

Other than that I can't see why your code won't work, have you tried stepping through it?
 
Upvote 0

Forum statistics

Threads
1,223,893
Messages
6,175,242
Members
452,623
Latest member
russelllowellpercy

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