Trigger a macro via a hyperlink

ifu06416

New Member
Joined
Sep 5, 2011
Messages
44
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
 

Some videos you may like

Excel Facts

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.

Norie

Well-known Member
Joined
Apr 28, 2004
Messages
76,271
Office Version
  1. 365
Platform
  1. Windows
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?
 

Watch MrExcel Video

Forum statistics

Threads
1,127,653
Messages
5,626,098
Members
416,161
Latest member
David1966Lewis

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
Top