Private sub to generate Text

howard

Well-known Member
Joined
Jun 26, 2006
Messages
6,595
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

Why are there 1,048,576 rows in Excel?
The Excel team increased the size of the grid in 2007. There are 2^20 rows and 2^14 columns for a total of 17 billion cells.
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,223,911
Messages
6,175,337
Members
452,637
Latest member
Ezio2866

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