We help IT Professionals succeed at work.

Excel - How to Add Hyperlink to Plain Text

Excel 2013
Windows 7

I have a list of names and dates all in one column that include hyperlinks. I expanded the contents of each cell to multiple columns. But, in doing so, I lost the hyperlinks.

I need a formula or Macro that takes the hyperlink from one cell in COL A and applies it to the adjacent cell in COL B, but I need to be able to tell it what SRC column and what DEST column to use; it's not always A and B.

NOTE: Only the first cell of the expanded data needs the hyperlink.

Original Data - This shows the first Column that contains the original data and the adjacent Columns that have been expanded - (copy/paste this sample data to your Excel spreadsheet and then add any hyperlink by hand to first Column cells for testing)

NOTE: To retain the proper layout in Excel, you may need to paste the code first into a plain text editor such as Notepad, then copy and paste into Excel.
Last2, First2 (1079-1142)	Last2	First2	1079	1142
First3 Last3, (1098-1179)	First3 Last3		1098	1179
Last1, First1 (1986)	Last1	First1		1986
Last4, (1983)	Last4			1983

Open in new window

The result should be that the first cell in the adjacent data will contain the hyperlink from it's source cell on the left. For example, "Last2" in Cell B1 will contain the hyperlink from "Last2, First2 (1079-1142)" in Cell A1.
Watch Question

Operations Manager
I found a solution:

'   This routine will copy ONLY the hyperlinks from the source cells
'   to the destination cells without changing the text in the destination
'   cells
'   SETUP:
'       Destination column in the spreadsheet must contain the text you want
'       Change Range Values in this code before running
Sub CopyHyperlinks()
    Dim DEST As Range           ' Specify which Column below, eg. ("B1")
    Dim SEARCH_RANGE As Range   ' Specify which rows contain the Source hyperlinks
    Dim SOURCE As Range         ' Dependent on SearchRange being initialized
    Set SEARCH_RANGE = Sheets(1).Range("A1:A99") ' <<< CHANGE THIS
    Set DEST = Sheets(1).Range("B1")                ' <<< CHANGE THIS
        If SOURCE.Hyperlinks.Count > 0 Then
            DEST.Hyperlinks.Add DEST, _
        End If
        Set DEST = DEST(2, 1)
    Next SOURCE
End Sub

Open in new window