Highlight the cell after clicking on the hyperlink in the cell

KTSARA

New Member
Joined
Nov 18, 2019
Messages
34
Hello experts,
I have an excel table which has hyperlinks in column D. I want to change the color of the cell to green after clicking on the hyperlink. What I want is not to highlight the active cell. I want the cell to have its color permanently after clicking on the hyperlink once. Can anyone of you tell me if this is possible? If it is possible can anyone of you experts help me to get this done.
I found several codes which highlight the cells linked by a hyperlink, but they are not a match to my requirement. Any help from you is highly appreciated.
Thanks a lot in advance.
 

Excel Facts

What is =ROMAN(40) in Excel?
The Roman numeral for 40 is XL. Bill "MrExcel" Jelen's 40th book was called MrExcel XL.
Hi, right click the sheet that contains the hyperlinks, choose "View Code" and past the following code into the sheets code module.

VBA Code:
Private Sub Worksheet_FollowHyperlink(ByVal Target As Hyperlink)
Target.Range.Interior.Color = vbGreen
End Sub

Save the workbook as a macro enabled workbook (.xlsm)
 
Upvote 0
Hi, right click the sheet that contains the hyperlinks, choose "View Code" and past the following code into the sheets code module.

VBA Code:
Private Sub Worksheet_FollowHyperlink(ByVal Target As Hyperlink)
Target.Range.Interior.Color = vbGreen
End Sub

Save the workbook as a macro enabled workbook (.xlsm)
Hello,
Thank you so much for taking your time to reply my question. I pasted the code, but still nothing happens. I have the below formula in my hyperlink cell. Does it affect the code?

=HYPERLINK("mailto:"&C2&"?subject="&"Service Reminder"&"&cc="&"l.w@adv.world"&"&body="&"There is a Service scheduled on "&$B$2,"Send Notification")

Thanks a lot in advance
 
Upvote 0
I have the below formula in my hyperlink cell. Does it affect the code?

Hi, yes it does.

You could try this instead - still in the worksheets code module.

VBA Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Left(Target.Formula, 11) = "=HYPERLINK(" Then
    Target.Interior.Color = vbGreen
End If
End Sub
 
Upvote 0
Hi, yes it does.

You could try this instead - still in the worksheets code module.

VBA Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Left(Target.Formula, 11) = "=HYPERLINK(" Then
    Target.Interior.Color = vbGreen
End If
End Sub
Hello,
This works perfectly. Many thanks for your valuable time and effort. :)
 
Upvote 0

Forum statistics

Threads
1,223,228
Messages
6,170,871
Members
452,363
Latest member
merico17

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