10

I think I must be going mad here, what I want to do is to write a simple Excel formula that performs an IF test, and if the result is false I want to hyperlink some text, if it is true I want to display some text which is not hyperlinked.

So for example -

=IF(1=1,"1",HYPERLINK("2"))

this returns 1 as you would expect, but the 1 is hyperlinked - I only want to hyperlink if the value is 2.

Surely this is possible? Thanks in advance for any advice!

1
  • Man, this limitation of Excel is a shame... (and so is the inability to insert multiple links in a single cell)
    – Sébastien
    Commented Feb 16, 2015 at 13:02

1 Answer 1

12

This happens because when Excel sees the HYPERLINK function in a cell it turns the entire cell into a "followable" cell so that links will work.

The workaround to avoiding the error message "The address of the site is not valid", which occurs when the hyperlink is turned on for the cell but the link has nowhere to go, is to give Excel a link that goes nowhere by referencing the current cell address.

For example:

=IF(
    1 = 2,
    HYPERLINK("https://example.com", "Link to example.com"),
    HYPERLINK("#" & ADDRESS(ROW(), COLUMN()), "N/A")
)

ADDRESS(ROW(),COLUMN()) gives a reference to the current cell (e.g. $A$1), and HYPERLINK("#<reference>", ...) links to the referenced cell.

3
  • My results are a little different. If I paste your formula into a cell, and then move the mouse directly over the number 1, the cursor changes to a hand. If I click, I get and "address not valid" message. If I then change it to IF(1=2... the appearance is the same, but the link works. If I start with IF(1=2... I get the exact same results. I never get a blue underlined link. Commented Jul 6, 2012 at 19:52
  • 2
    Thank you, sending the link to a dummy destination of "" appears to do the trick here.
    – McVicar
    Commented Jul 11, 2012 at 13:49
  • 1
    note, apply conditional formatting based on the link text to make them not look like links if they're not links. Or moreover, do the reverse: set the links to be black and non-underlined, and then apply conditional formatting to make them blue and underlined if they actually are links.
    – Some_Guy
    Commented Jul 13, 2017 at 14:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.