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

Does the VLOOKUP table have to be sorted?
No! when you are using an exact match, the VLOOKUP table can be in any order. Best-selling items at the top is actually the best.
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,991
Messages
6,122,628
Members
449,095
Latest member
bsb1122

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