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

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".
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,214,377
Messages
6,119,183
Members
448,872
Latest member
lcaw

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