Conditional Formatting - if there is hyperlink

rexwrx

New Member
Joined
Aug 29, 2006
Messages
16
Hi again everyone,

I've posted this similar question, but it's not on hyperlink.

Anyway, i want to check in a given cell, if I put a hyperlink, i want it to be GREEN in colour, and if i remove the hyperlink, it returns to YELLOW.

Can I do this with UDF, via VBA?

cheers
 

Excel Facts

Best way to learn Power Query?
Read M is for (Data) Monkey book by Ken Puls and Miguel Escobar. It is the complete guide to Power Query.
how are you setting up the hyperlink? via a hyperlink() formula, or more directly?
 
Upvote 0
just using right-click and "Add Hyperlink".

Whichever way is easier, i'm open to suggestions.
 
Upvote 0
you could create an hasHyperlink() UDF and then use conditional formatting to change the color of the cell. Example:
Code:
Public Function hasHyperlink(ref As Range) As Boolean
   hasHyperlink = ref.Hyperlinks.Count > 0
End Function

hth,
Giacomo
 
Upvote 0
yep, essentially that's what i've done whilst waiting for a reply.
If rng.Hyperlinks.Count > 0 Then
HasLink = True
If Len(HasLink) > 0 Then
'HasLink = rng.Hyperlinks(1).SubAddress
HasLink = True
'rng.HorizontalAlignment = xlCenter
'rng.Interior.ColorIndex = 36
'rng.Interior.Pattern = xlSolid
End If
Else
HasLink = False
' rng.HorizontalAlignment = xlCenter
' rng.Interior.ColorIndex = 36
' rng.Interior.Pattern = xlSolid

End If

and yes it works with conditional formatting.

However, when i remove the link, the cell becomes white, and the format returns to the standard format (left aligned)

I need it to return to the center aligned and with light yellow background with border around the cells

does the code above look right? especially the part where i tried to "FORMAT" the cells???
 
Upvote 0

Forum statistics

Threads
1,217,675
Messages
6,137,925
Members
450,099
Latest member
Pushbutton

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