Private sub to generate Text

howard

Well-known Member
Joined
Jun 26, 2006
Messages
6,603
Office Version
  1. 2021
Platform
  1. Windows
I have hyperlinks on sheet "Data" in G17 to G23. I tried to write a Private sub to generate text "Select Macro on sheet" In Col I in the same Row as where the hyperlink has been selected



For eg If I click ion G18 , then this text to be generated in I18

I have written code but cannot get it to generate the text in Col I in the same row as the hyperlink tht has been clicked

Kindly amend my code

Code:
 Private Sub Worksheet_BeforeRightClick(ByVal Target As Range, Cancel As Boolean)
    Dim rng As Range
    Set rng = Range("G17:G23")  


    If Not Intersect(Target, rng) Is Nothing And Target.Hyperlinks.Count > 0 Then
        ' If yes, update the corresponding cell in column I with the message
        Cells(Target.Row, "I").Value = "Select Macro on sheet
    End If
End Sub
 

Excel Facts

Excel Joke
Why can't spreadsheets drive cars? They crash too often!
This works for me when I click the hyperlink:
VBA Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    If Not Intersect(Target, Range("G17:G23")) Is Nothing And Target.Hyperlinks.Count > 0 Then
        Cells(Target.Row, "I").Value = "Select Macro on sheet"
    End If
End Sub
 
Upvote 0
Click here to download your file. I'm not sure how you created the hyperlinks but they were creating the problem. I re-created the hyperlinks using the "Hyperlink" button on the "Insert" tab in the menu at the top and the macro works properly.
 
Upvote 0
Solution
Thanks for your help. I used a formula to generate a hyperlink, but it caused the issue
 
Upvote 0

Forum statistics

Threads
1,224,830
Messages
6,181,225
Members
453,025
Latest member
Hannah_Pham93

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