Change cell colour, after hyperlink activated

russelldt

Board Regular
Joined
Feb 27, 2021
Messages
158
Office Version
  1. 365
Platform
  1. MacOS
I have 3 cells (A1, A2 and A3) that have hyperlinked Mailto functions. When i have sent the email hyperlinked in cell A1, i want that cell to change fill colour from "No Color" to green. The change must be permanent so that it's visible that the email has been sent each time the file is opened. The other 2 cells should operate the same.

Thank you
 

Excel Facts

What did Pito Salas invent?
Pito Salas, working for Lotus, popularized what would become to be pivot tables. It was released as Lotus Improv in 1989.
Give this a try. Add this sub to the sheet where your hyperlinks exist:
Private Sub Worksheet_selectionchange(ByVal Target As Range)

If Not Intersect(Range("A1:A3"), Target) Is Nothing Then

With Selection.Interior
.Pattern = xlSolid
.PatternColorIndex = xlAutomatic
.Color = 5287936
.TintAndShade = 0
.PatternTintAndShade = 0
End With
End If
End Sub
 
Upvote 0
Give this a try. Add this sub to the sheet where your hyperlinks exist:
Private Sub Worksheet_selectionchange(ByVal Target As Range)

If Not Intersect(Range("A1:A3"), Target) Is Nothing Then

With Selection.Interior
.Pattern = xlSolid
.PatternColorIndex = xlAutomatic
.Color = 5287936
.TintAndShade = 0
.PatternTintAndShade = 0
End With
End If
End Sub
Thanks, i will give it a shot.
 
Upvote 0
No luck, the cell fill does not change. I am using MAC, and this might be an issue.
Are you ABSOLUTELY sure that you placed this in the correct sheet module, and have VBA enabled?

The most common mistake that people make with Event Procedure VBA code is that they put it in the wrong module.
If you place it in the wrong place, it will NOT run automatically.

An easy way to make sure you have put it in the correct place is to right-click on the sheet tab name at the bottom of the worksheet, select "View Code", and paste the code in the VB Editor window that pops up.
 
Upvote 0
Are you ABSOLUTELY sure that you placed this in the correct sheet module, and have VBA enabled?

The most common mistake that people make with Event Procedure VBA code is that they put it in the wrong module.
If you place it in the wrong place, it will NOT run automatically.

An easy way to make sure you have put it in the correct place is to right-click on the sheet tab name at the bottom of the worksheet, select "View Code", and paste the code in the VB Editor window that pops up.
Ah...you are a genius, Thanks. can you tone down the colour to a lighter green ?

Thanks again
 
Upvote 0
Ah...you are a genius, Thanks. can you tone down the colour to a lighter green ?

Thanks again
You can pick whatever color you want.
Just turn on the Macro Recorder, and choose the color you want, and then stop the Macro Recorder.
Then view your recorded VBA code, and copy and paste the color code you recorded over the "5287936" Candyman provided in his code to you.
 
Upvote 0
You can pick whatever color you want.
Just turn on the Macro Recorder, and choose the color you want, and then stop the Macro Recorder.
Then view your recorded VBA code, and copy and paste the color code you recorded over the "5287936" Candyman provided in his code to you.
I have run into a problem. Here is my script, as you can see the range is columns AN and AO. Some of the cells are always blank (ie dont have a hyperlink). The problem i am having is that every cell i click in these two columns changes colour.

Private Sub Worksheet_selectionchange(ByVal Target As Range)

If Not Intersect(Range("An:ao"), Target) Is Nothing Then

With Selection.Interior
.Pattern = xlSolid
.PatternColorIndex = xlAutomatic
.Color = 5287936
.TintAndShade = 0
.PatternTintAndShade = 0
End With
End If
End Sub
 
Upvote 0
Try this:
VBA Code:
Private Sub Worksheet_selectionchange(ByVal Target As Range)

    Dim rng As Range
    Dim cell As Range
    
    Set rng = Intersect(Range("AN:AO"), Target)
    If rng Is Nothing Then Exit Sub
    
    For Each cell In rng
        If cell <> "" Then cell.Interior.Color = 5287936
    Next cell

End Sub
 
Upvote 0
Try this:
VBA Code:
Private Sub Worksheet_selectionchange(ByVal Target As Range)

    Dim rng As Range
    Dim cell As Range
   
    Set rng = Intersect(Range("AN:AO"), Target)
    If rng Is Nothing Then Exit Sub
   
    For Each cell In rng
        If cell <> "" Then cell.Interior.Color = 5287936
    Next cell

End Sub
Thanks Joe, that does the trick for me
 
Upvote 0

Forum statistics

Threads
1,214,957
Messages
6,122,466
Members
449,086
Latest member
kwindels

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