How do I copy hyperlink only (and not text) to another cell?

2

I have a spreadsheet where column A displays names. There are a few hundred names and each has a different hyperlink (which links to that person's web page). I want to transfer those hyperlinks across to a different column which has different text in and no hyperlinks.

Not every cell in column A has a hyperlink. There are groups of cells merged together, so A2:A7 has one link, A8:A13 the next, A9:10 the next (i.e. number of cells merged is not uniform).

e.g. where A2:A7 reads "Bob" and links to www.bob.com, I want I2:I7, which reads, "Smith," and does not link to anything, to link to www.bob.com. I want to do this repeatedly, copying links from A2:A579 into I2:I579.

The information is copied from a table within a web page, and that is where the hyperlinks come from.

OfficeLackey

Posted 2014-06-04T15:16:41.637

Reputation: 25

Question was closed 2014-06-11T18:43:07.330

2Here is an important piece of information you've left out of your question; How are the existing hyperlinks created in the cells? Do they use the HYPERLINK function or are they embedded using Insert Hyperlink from the Insert ribbon? – CharlieRB – 2014-06-04T15:42:21.447

This question is so unclear... Have the information is in comments. Why explain the order was incorrect if you've fixed it, it just adds waffle to your question... Please click here to edit your question and explain exactly how the information is populated in your Excel document. As the question is now, IMO it's unclear what you want and I have voted to close the question

– Dave – 2014-06-05T10:27:06.300

@DaveRook I'm sorry, this is the first time I have used this forum and I didn't think to edit the question rather than comment. I'm doing my best to present the information such that people can help me. Hope this is better. Please tell me what you need to know if I haven't expressed myself clearly enough still. – OfficeLackey – 2014-06-05T13:35:24.237

Right, your question is now clear. However, I suspect you will want to do this multiple times? If that is the case, then what is the logic? Do you always want to remove A1 hyperlink and replace it with A10 hyperlink? And then again with B1 and B10, C1 and C10 etc? – Dave – 2014-06-05T13:54:51.627

@DaveRook Please see updated question. – OfficeLackey – 2014-06-05T13:59:10.610

@Madball73 I had already looked at that question and it is not the same as mine - I have since revised the phrasing of my question to clarify – OfficeLackey – 2014-06-05T14:36:48.687

@CharlieRB See edit – OfficeLackey – 2014-06-05T14:37:05.823

Answers

1

This macro will help

Sub SwapIt()

For i = 2 To 579

If Range("A" & i).Value <> "" And Range("I" & i).Value <> "" Then

    Dim newLink As String ' the new link string needs a place to live... just like me!

    If Range("A" & i).Hyperlinks.Count = 1 Then
    newLink = Range("A" & i).Hyperlinks(1).Address ' Get the old horrible link :)
    Range("I" & i).Hyperlinks.Add anchor:=Range("I" & i), Address:=Range("I" & i) ' horrible hack, just to get it to a link
    Range("I" & i).Hyperlinks(1).Address = newLink '' replace with the new link... Much better. Like a ray of sunshine
    End If
End If

Next i

End Sub

This will move the hyperlink From A2 to I2, then A3 to I3 etc

Dave

Posted 2014-06-04T15:16:41.637

Reputation: 24 199

Updated the code, this will now do from row 2 to 579 – Dave – 2014-06-05T14:06:25.570

I am getting: Run time error 9 - subscript out of range. – OfficeLackey – 2014-06-05T14:11:07.810

Range("I" & i).Hyperlinks(1).Address = newLink – OfficeLackey – 2014-06-05T14:14:59.643

The I column does not have any hyperlinks originally (which I have stated in question edit) - does this make a difference to your code? – OfficeLackey – 2014-06-05T14:16:40.860

No, my original question said each has different text and that I want to move the hyperlinks from A to I. I realised that I had not explicitly stated there were no hyperlinks in I, and updated question appropriately. Sorry if I am being unhelpful - I am doing my best to explain my problem succinctly! – OfficeLackey – 2014-06-05T14:28:51.027

Updated - I've had to hack it in due to time restraints, but, I will still work – Dave – 2014-06-05T14:42:36.663

Now getting same Run time error on: newLink = Range("A" & i).Hyperlinks(1).Address - sorry to be a pain again =S – OfficeLackey – 2014-06-05T14:47:59.403

Ah! No. That would be the issue. Will edit question. Sorry. – OfficeLackey – 2014-06-05T14:56:27.123

Updated again for you. OfficeLackey, if you're having to edit your question this often, you may need to consider asking a new question. You can ask many questions. The idea isn't to ask 1 question, and keep updating the question when you realise something isn't quite right etc – Dave – 2014-06-05T15:01:07.703

See edit - I am aware this is rather complicated and I'm probably not helping. Very grateful for your time. – OfficeLackey – 2014-06-05T15:02:02.677

Can you confirm if it works or not. – Dave – 2014-06-05T15:46:02.967

Yes works perfectly — many thanks for your help! – OfficeLackey – 2014-06-05T20:13:19.057