VBA Hyperlink trigger macro

APML

Board Regular
Joined
Sep 10, 2021
Messages
216
Office Version
  1. 365
Hi All, the following VBA is meant to trigger macros if the hyperlink at B4 or D4 is activated, however D4 doesn't trigger its macro,
All help greatly appreciated

Private Sub Worksheet_FollowHyperlink(ByVal Target As Hyperlink)



If Target.Range.Address = "$B$4" Then
Call NewRow

ElseIf Target.Range.Address = "$D$4" Then
Call DeleteRow

End If

End Sub
 

Excel Facts

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple
Might start with putting a debug.print "some name" after each then statement to see if it's triggering for each condition...
 
Upvote 0
The following code works for me.


VBA Code:
Private Sub Workbook_SheetFollowHyperlink(ByVal Sh As Object, ByVal Target As Hyperlink)

    If Target.Range.Address = "$B$4" Then
        MsgBox ("Clicked B4")
    
    ElseIf Target.Range.Address = "$D$4" Then
        MsgBox ("Clicked D4")
    
    End If

End Sub

You did put this code in the workbook section of the VBA editor instead of its own module, right?
 
Upvote 0

Forum statistics

Threads
1,214,822
Messages
6,121,767
Members
449,049
Latest member
greyangel23

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