1

I have a workbook that has a column which contains the titles of different documents which are published to a website (B4:B6). Another column contains the URLs for those documents (C4:C6). The URL is created by the website when the document is uploaded, and always appends a number to the URL that is not predictable ahead of time.

Sample spreadsheet

I have a user who is used to manually inserting a hyperlink into the cell which contains the title, so that the title cell points to the URL. He wants the title cells to be hyperlinked, understands the need to have the hyperlink in its own cell for reference purposes, but doesn't want to re-type or copy-paste the URL. How do I setup the URL cells (C4:C6) to check the title cells for embedded hyperlinks, and if it finds one, to replicate it in the appropriate URL cell?

Alternatively, how do I setup the title cells to check the URL cells for text, and if it finds some, to automatically apply that text as a hyperlink in the appropriate title cell?

And worst of all, how do I do this without using VBA/macros?

Put another way:

Current state: User manually applies hyperlink to title in column B. User also manually enters text of the URL in column C.

Desired state (option 1): User manually applied hyperlink to title in column B. Text of the URL is automatically extracted from the hyperlink (not the text of the title) and placed in column C.

Desired state (option 2): User manually enters text of the URL in column C. The URL is automatically applied as an embedded hyperlink in the cell containing the title in column B.

Helper columns are totally fine if necessary.

2
  • So if "Document Title" rows have a Hyperlink, you want to extract that URL in the "External Link" column. If it does not have a hyperlink, you want to add one? So under the www.fakewebsite.com/how-to-eat-worms, you want say www.fakewebsite.com/how-to-dig-a-hole?
    – BruceWayne
    Apr 27, 2017 at 15:49
  • @BruceWayne The solution doesn't have to do both - either option would work fine. Extracting a hyperlink from column B (if present) to column C is adequate. Applying a hyperlink from column C (if present) to column B is also adequate. What I don't need is for column C to automatically contain a hyperlink based on the text of column B, as the URL does not always follow the format shown in my example. For instance, the URL for the document "How to Dig a Hole" may end up being www.fakewebsite.com/how-to-dig-a-hole-27635 .
    – Piripero
    Apr 27, 2017 at 16:10

2 Answers 2

1

If you want to use formulas and links do not follow a simple pattern then you need to copy your titles into another column (or sheet) and refer to them in your hyperlink formula.

HYPERLINK("link","copied_title")

Look below;excel_screenshot

For the other desired option, you still have to use VBA but maybe only a user-defined option would be sufficient as described in one of the answers in this thread: Extracting URLs from Hyperlinks


VBA Solution


If you are interested in VBA, something like this would help:

Sub hyperlink_title()
    Dim i As Integer
    Dim wsh as Worksheet
    Set wsh = ThisWorkbook.ActiveSheet

    i = 4
    With wsh
    While .Cells(i, 2) <> ""

        ActiveSheet.Hyperlinks.Add Anchor:=.Cells(i, 2), Address:=.Cells(i, 3).Value, _
        TextToDisplay:=.Cells(i, "B").Value2

        i = i + 1

    Wend

End Sub
4
  • Unfortunately I can't use VBA to solve this issue, as I need this workbook to live on Sharepoint.
    – Piripero
    Apr 27, 2017 at 16:09
  • If you don't want use vba then you need to have an extra column. Let me update my answer. There's no work around.
    – M--
    Apr 27, 2017 at 16:16
  • I think your formula option is getting closer - it would allow the user to enter the title in one cell, the URL in a second cell, and a third cell then displays the hyperlinked title (if I'm using the formula properly). The problem with this solution is that it relies on all three columns remaining unhidden, in a workbook that already has many columns (my sample spreadsheet is a simplification). Is there any way to automatically apply a hyperlink to a cell?
    – Piripero
    Apr 27, 2017 at 16:37
  • >Helper columns are totally fine if necessary.< NO, as I said there's no workaround. You need that column.
    – M--
    Apr 27, 2017 at 16:39
0

This formula will look at a cell, and if there's a hyperlink (using the Hyperlink() formula), will return the URL. If there's no link and it's just text, it creates a link to http://www.fakewebsite.com/[text]:

=IFERROR(MID(FORMULATEXT(A2),SEARCH("http",FORMULATEXT(A2)),SEARCH(",",FORMULATEXT(A2))-SEARCH("http",FORMULATEXT(A2))-1),HYPERLINK("http://www.fakewebsite.com/"&SUBSTITUTE(A2," ","-")))

Note: If there's no "http", just replace "http" with "www" in the above formula. It works like this:

enter image description here

Edit: Per clarification, this will extract a link from "Document Title" column and just put some text if there's no link:

=IFERROR(MID(FORMULATEXT(A2),SEARCH("http",FORMULATEXT(A2)),SEARCH(",",FORMULATEXT(A2))-SEARCH("http",FORMULATEXT(A2))-1),"No Link")
2
  • Thanks, but this isn't quite what I'm looking for. The URL in my example is an oversimplification, and the true URLs will always have a number appended to them that is generated by the website when the page is created - so generating the URL is not as simple as appending the Document Title to the domain.
    – Piripero
    Apr 27, 2017 at 16:08
  • @Piripero - Please describe then in your OP what you need, and how it's going to work. Otherwise I suspect you'll start getting answers that don't do what you need, from the little amount of info you've given. Also, this formula can be adjusted if needed to grab whatever number...
    – BruceWayne
    Apr 27, 2017 at 16:11

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .