6
votes

Is it possible to create a hyperlink within an Excel cell which only uses a section of the cell text for the clickable link? I.E. would the below table mockup represent something that can be easily built in Excel 2010?

a mock up http://dl.dropbox.com/u/14119404/misc/Microsoft%20Excel%20-%20Book1_2012-04-16_14-24-47.jpg

I know that an entire cell can be made into a hyperlink easily, but not a specific part of the cell as far as I know.

By hyperlink I also refer to either

  • (a)another cell or,
  • (b)a web URL.

Thanks

5
Sorry to report - but link to dropbox returns 404rudolf_franek

5 Answers

15
votes

After creating the hyperlink you could format the text in the cell so that only the words of interest are underlined/blue. The hyperlink will still work, but obviously you can still have only one link per cell, and clicking anywhere in the text will trigger the hyperlink.

For example:

enter image description here

Sub Tester()

    Dim rng As Range

    Set rng = ActiveSheet.Range("A1")

    rng.Parent.Hyperlinks.Add Anchor:=rng, Address:="", SubAddress:= _
        "Sheet1!A10", TextToDisplay:="this is long text"

    With rng.Font
        .ColorIndex = xlAutomatic
        .Underline = xlUnderlineStyleNone
    End With

    With rng.Characters(Start:=9, Length:=4).Font
        .Underline = xlUnderlineStyleSingle
        .Color = -4165632
    End With

End Sub
5
votes

I needed to link to a filename displayed in a cell, so here is what worked for me:

ActiveSheet.Hyperlinks.Add Anchor:=Cells(row, column), Address:=file.Path, TextToDisplay:=file.Path
3
votes

This isn't possible in Excel. Hyperlinks are associated with entire cells.

If you look at the documentation for the Excel hyperlink object, you can see that it's associated with a Range. If it were possible to associate hyperlinks with a span within the cell, the Hyperlink object would need to have an associated Range and Characters object.

0
votes

The above one liner was very helpful... since I'm new, I couldn't comment. So here is my variation of the above that takes each row on a worksheet and builds a URL from a value on the row.

CHGRow = 3
Worksheets("Page 1").Select
Cells(CHGRow, 1).Select

Do Until Application.CountA(ActiveCell.EntireRow) = 0

    URLVal = "https://our_url_here?some_parameter=" & Cells(CHGRow, cNumber)
    URLText = Cells(CHGRow, cNumber)
    ActiveSheet.Hyperlinks.Add Anchor:=Cells(CHGRow, cURL), Address:=URLVal, TextToDisplay:=URLText

    CHGRow = CHGRow + 1
    Cells(CHGRow, 1).Select

Loop
0
votes

I'd just make your one row into two rows, merge the cells in the columns you need to have it appear to be a single row and when you get to the cell that needs the hyperlink then you put the words on the top cell and the link in the cell below. It will look fine as a non-techy workaround.