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

Can you sort left to right?
To sort left-to-right, use the Sort dialog box. Click Options. Choose "Sort left to right"

PaddyD

MrExcel MVP
Joined
May 1, 2002
Messages
14,234
how are you setting up the hyperlink? via a hyperlink() formula, or more directly?
 

rexwrx

New Member
Joined
Aug 29, 2006
Messages
16
just using right-click and "Add Hyperlink".

Whichever way is easier, i'm open to suggestions.
 

giacomo

Well-known Member
Joined
Feb 20, 2002
Messages
1,796
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
 

rexwrx

New Member
Joined
Aug 29, 2006
Messages
16
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???
 

Forum statistics

Threads
1,141,019
Messages
5,703,771
Members
421,315
Latest member
awaisnazir139

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
Top